90-stat.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /* -*-comment-start: "//";comment-end:""-*-
  2. * GNU Mes --- Maxwell Equations of Software
  3. * Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
  4. *
  5. * This file is part of GNU Mes.
  6. *
  7. * GNU Mes is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * GNU Mes is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include <mes/lib.h>
  21. #include <errno.h>
  22. #include <stdio.h>
  23. #include <string.h>
  24. #include <fcntl.h>
  25. #include <sys/stat.h>
  26. #if __i386__ || __arm__
  27. #define stat xstat
  28. struct stat
  29. {
  30. unsigned long st_dev;
  31. unsigned long st_ino;
  32. unsigned short st_mode;
  33. unsigned short st_nlink;
  34. unsigned short st_uid;
  35. unsigned short st_gid;
  36. unsigned long st_rdev;
  37. long st_size;
  38. unsigned int st_blksize;
  39. unsigned int st_blocks;
  40. long st_atime;
  41. unsigned long st_atime_usec;
  42. long st_mtime;
  43. unsigned long st_mtime_usec;
  44. long st_ctime;
  45. unsigned long st_ctime_usec;
  46. unsigned int __foo0;
  47. unsigned int __foo1;
  48. };
  49. #endif
  50. int
  51. main ()
  52. {
  53. // char buf[20];
  54. // strcpy (buf, "Hello");
  55. // eputs ("buf="); eputs (buf); eputs ("\n");
  56. // strcat (buf, ", ");
  57. // eputs ("buf="); eputs (buf); eputs ("\n");
  58. // strncat (buf, "world!XXX", 6);
  59. // eputs ("buf="); eputs (buf); eputs ("\n");
  60. // if (strcmp (buf, "Hello, world!"))
  61. // return 1;
  62. // char *name = "boo";
  63. // errno = 0;
  64. // fprintf (stderr, "%s: %s\n", name, strerror (errno));
  65. int fd = open ("../COPYING", 0);
  66. struct stat sbuf;
  67. if (fd < 0)
  68. return 2;
  69. int r = fstat (fd, &sbuf);
  70. if (r < 0)
  71. return 1;
  72. eputs ("st_dev=");
  73. eputs (itoa (sbuf.st_dev));
  74. eputs ("\n");
  75. eputs ("st_ino=");
  76. eputs (itoa (sbuf.st_ino));
  77. eputs ("\n");
  78. eputs ("st_mode=");
  79. eputs (itoa (sbuf.st_mode));
  80. eputs ("\n");
  81. eputs ("st_nlink=");
  82. eputs (itoa (sbuf.st_nlink));
  83. eputs ("\n");
  84. eputs ("st_uid=");
  85. eputs (itoa (sbuf.st_uid));
  86. eputs ("\n");
  87. eputs ("st_gid=");
  88. eputs (itoa (sbuf.st_gid));
  89. eputs ("\n");
  90. eputs ("st_rdev=");
  91. eputs (itoa (sbuf.st_rdev));
  92. eputs ("\n");
  93. eputs ("st_size=");
  94. eputs (itoa (sbuf.st_size));
  95. eputs ("\n");
  96. eputs ("st_blksize=");
  97. eputs (itoa (sbuf.st_blksize));
  98. eputs ("\n");
  99. eputs ("st_blocks=");
  100. eputs (itoa (sbuf.st_blocks));
  101. eputs ("\n");
  102. eputs ("st_atime=");
  103. eputs (itoa (sbuf.st_atime));
  104. eputs ("\n");
  105. //eputs ("st_atime_nsec="); eputs (itoa (sbuf.st_atime_nsec)); eputs ("\n");
  106. eputs ("st_mtime=");
  107. eputs (itoa (sbuf.st_mtime));
  108. eputs ("\n");
  109. //eputs ("st_mtime_nsec="); eputs (itoa (sbuf.st_mtime_nsec)); eputs ("\n");
  110. eputs ("st_ctime=");
  111. eputs (itoa (sbuf.st_ctime));
  112. eputs ("\n");
  113. //eputs ("st_ctime_nsec="); eputs (itoa (sbuf.st_ctime_nsec)); eputs ("\n");
  114. eputs ("size:");
  115. eputs (itoa (sizeof (struct stat)));
  116. eputs ("\n");
  117. return 0;
  118. }