comparison tests/test-readlink.c @ 12060:95a12a00ea4f

readlink: document portability issue with symlink length Per comments in areadlink, ERANGE on a too-small buffer is expected on some platforms; making the readlink module guarantee GNU behavior of truncated contents is counter-productive, since we would be duplicating areadlink to learn a-priori how large to make the buffer, and since truncated contents are not as useful. * doc/posix-functions/lstat.texi (lstat): Mention that some file systems have bogus st_size on symlinks, and mention the areadlink-with-size module. * doc/posix-functions/fstatat.texi (fstatat): Likewise. * doc/posix-functions/readlink.texi (readlink): Mention the areadlink module, and ERANGE failure. * doc/posix-functions/readlinkat.texi (readlinkat): Likewise. * tests/test-readlink.c (main): Relax test for AIX, HP-UX. Signed-off-by: Eric Blake <ebb9@byu.net>
author Eric Blake <ebb9@byu.net>
date Mon, 21 Sep 2009 14:40:20 -0600
parents 6babf16a67dd
children c47da311af77
comparison
equal deleted inserted replaced
12059:6babf16a67dd 12060:95a12a00ea4f
95 ASSERT (buf[i] == (char) 0xff); 95 ASSERT (buf[i] == (char) 0xff);
96 } 96 }
97 { 97 {
98 size_t len = strlen (BASE "dir"); 98 size_t len = strlen (BASE "dir");
99 /* When passing too small of a buffer, expect the truncated 99 /* When passing too small of a buffer, expect the truncated
100 length. However, a size of 0 is not portable enough to 100 length, or an ERANGE failure. However, a size of 0 is not
101 test. */ 101 portable enough to test. */
102 ASSERT (readlink (BASE "link", buf, 1) == 1); 102 ssize_t result;
103 ASSERT (buf[0] == BASE[0]); 103 errno = 0;
104 result = readlink (BASE "link", buf, 1);
105 if (result == -1)
106 {
107 ASSERT (errno == ERANGE);
108 ASSERT (buf[0] == (char) 0xff);
109 }
110 else
111 {
112 ASSERT (result == 1);
113 ASSERT (buf[0] == BASE[0]);
114 }
104 ASSERT (buf[1] == (char) 0xff); 115 ASSERT (buf[1] == (char) 0xff);
105 ASSERT (readlink (BASE "link", buf, len) == len); 116 ASSERT (readlink (BASE "link", buf, len) == len);
106 ASSERT (strncmp (buf, BASE "dir", len) == 0); 117 ASSERT (strncmp (buf, BASE "dir", len) == 0);
107 ASSERT (buf[len] == (char) 0xff); 118 ASSERT (buf[len] == (char) 0xff);
108 ASSERT (readlink (BASE "link", buf, sizeof buf) == len); 119 ASSERT (readlink (BASE "link", buf, sizeof buf) == len);