- fprintf(stderr, "write (normal) %s\n", strerror(errno));
- exit(1);
- }
-
- if (argc == 3) {
- fprintf(stderr, "closing %s\n", fname);
- rc = close(fd);
- if (rc) {
- fprintf(stderr, "close (normal) %s\n", strerror(errno));
- exit(1);
- }
-
- fprintf(stderr, "opening %s\n", fname2);
- fd = open(fname2, O_RDWR);
- if (fd == -1) {
- fprintf(stderr, "open (unlink) %s\n", strerror(errno));
- exit(1);
- }
-
- fprintf (stderr, "unlinking %s\n", fname2);
- rc = unlink(fname2);
- if (rc) {
- fprintf(stderr, "unlink %s\n", strerror(errno));
- exit(1);
- }
-
- if (access(fname2, F_OK) == 0) {
- fprintf(stderr, "%s still exists\n", fname2);
- exit(1);
- }
- } else {
- printf("unlink %s and press enter\n", fname);
- getc(stdin);
- }
-
- if (access(fname, F_OK) == 0) {
- fprintf(stderr, "%s still exists\n", fname);
- exit(1);
- }
+ fprintf(stderr, "write (normal) %s (rc %d)\n",
+ strerror(errno), rc);
+ exit(1);
+ }
+
+ if (argc == 3) {
+ fprintf (stderr, "unlinking %s\n", fname2);
+ rc = unlink(fname2);
+ if (rc) {
+ fprintf(stderr, "unlink %s\n", strerror(errno));
+ exit(1);
+ }
+ } else {
+ printf("unlink %s and press enter\n", fname);
+ getc(stdin);
+ }
+
+ fprintf(stderr, "accessing (1)\n");
+ if (access(fname, F_OK) == 0) {
+ fprintf(stderr, "%s still exists\n", fname2);
+ exit(1);
+ }
+
+ fprintf(stderr, "seeking (1)\n");
+ rc = lseek(fd, 0, SEEK_SET);
+ if (rc) {
+ fprintf(stderr, "seek %s\n", strerror(errno));
+ exit(1);
+ }
+
+ fprintf(stderr, "accessing (2)\n");
+ if (access(fname, F_OK) == 0) {
+ fprintf(stderr, "%s still exists\n", fname);
+ exit(1);
+ }
+
+ fprintf(stderr, "fstat...\n");
+ rc = fstat(fd, &st);
+ if (rc) {
+ fprintf(stderr, "fstat (unlink) %s\n", strerror(errno));
+ exit(1);
+ }
+ if (st.st_nlink != 0)
+ fprintf(stderr, "st_nlink = %d\n", (int)st.st_nlink);