diff options
author | Josef Karthauser <joe@FreeBSD.org> | 2000-06-17 11:09:24 +0000 |
---|---|---|
committer | Josef Karthauser <joe@FreeBSD.org> | 2000-06-17 11:09:24 +0000 |
commit | 8c7bdc130e70c930f58e483fb4922c02f3d24d86 (patch) | |
tree | da1ea697e1f657619b9b2f33373e5804a89850c4 /lib/libc/gen | |
parent | 7684b08b561d54e88e094318e306261947ce6e45 (diff) | |
download | src-8c7bdc130e70c930f58e483fb4922c02f3d24d86.tar.gz src-8c7bdc130e70c930f58e483fb4922c02f3d24d86.zip |
Modify strtofflags so that it returns a malloced string instead of a
pointer to a static buffer.
Notes
Notes:
svn path=/head/; revision=61746
Diffstat (limited to 'lib/libc/gen')
-rw-r--r-- | lib/libc/gen/strtofflags.3 | 27 | ||||
-rw-r--r-- | lib/libc/gen/strtofflags.c | 7 |
2 files changed, 30 insertions, 4 deletions
diff --git a/lib/libc/gen/strtofflags.3 b/lib/libc/gen/strtofflags.3 index f287c172cf73..10f86c935917 100644 --- a/lib/libc/gen/strtofflags.3 +++ b/lib/libc/gen/strtofflags.3 @@ -38,7 +38,7 @@ .Sh NAME .Nm fflagstostr , .Nm strtofflags -.Nd modify file flag bits +.Nd convert between file flag bits and their string names .Sh LIBRARY .Lb libc .Sh SYNOPSIS @@ -54,6 +54,19 @@ function returns a comma separated string of the file flags represented by .Fa flags . If no flags are set a zero length string is returned. .Pp +If memory cannot be allocated for the return value, +.Fn fflagstostr +returns +.Dv NULL . +.Pp +The value returned from +.Fn fflagstostr +is obtained from +.Fn malloc +and should be returned to the system with +.Fn free +when the program is done with it. +.Pp The .Fn strtofflags function takes a string of file flags, as described in @@ -66,13 +79,21 @@ On success returns 0, otherwise it returns non-zero and .Fa stringp is left pointing to the offending token. +.Sh ERRORS +The +.Fn fflagstostr +function +may fail and set errno for any of the errors specified for the library +routine +.Xr malloc 3 . .Sh SEE ALSO .Xr chflags 1 , .Xr chflags 2 , +.Xr malloc 3 .Sh HISTORY The -.Fn strtofflags -and .Fn fflagstostr +and +.Fn strtofflags functions first appeared in .Fx 4.0 . diff --git a/lib/libc/gen/strtofflags.c b/lib/libc/gen/strtofflags.c index d9d2dc4f37b2..4c9e8d562aa8 100644 --- a/lib/libc/gen/strtofflags.c +++ b/lib/libc/gen/strtofflags.c @@ -44,6 +44,7 @@ static const char rcsid[] = #include <sys/stat.h> #include <stddef.h> +#include <stdlib.h> #include <string.h> static struct { @@ -71,6 +72,7 @@ static struct { { "nouunlnk", UF_NOUNLINK, 0 }, { "nouunlink", UF_NOUNLINK, 0 } }; +#define longestflaglen 12 #define nmappings (sizeof(mapping) / sizeof(mapping[0])) /* @@ -82,11 +84,14 @@ char * fflagstostr(flags) u_long flags; { - static char string[128]; + char *string; char *sp, *dp; u_long setflags; int i; + if ((string = (char *)malloc(nmappings * (longestflaglen + 1))) == NULL) + return (NULL); + setflags = flags; dp = string; for (i = 0; i < nmappings; i++) { |