[Re-adding bug-gnulib back in CC. Please keep bug-gnulib in CC.] Benji Wiebe wrote: > Hey thanks a lot for the feedback Bruno and Tim! My C is sort of rusty > right now. I believe I've addressed all your concerns and suggestions in > the patch below. > > Thanks again!
It is better, but there are still (minor) things to tweak. Your mailer seems to break long lines; I cannot apply your patch after copy&pasting it. So, next times, can you please provide the patch as an attachment? > diff --git a/lib/getprogname.c b/lib/getprogname.c > index 744466ea9..e1f02f550 100644 > --- a/lib/getprogname.c > +++ b/lib/getprogname.c > @@ -51,6 +51,11 @@ > # include <sys/procfs.h> > #endif > > +#if defined __USLC__ || defined __sysv5__ Please use either #ifdef _SCO_DS or #ifdef __SCO_VERSION__, as discussed in the other mail. > +# include <fcntl.h> > +# include <stdlib.h> Now that you use strrchr(), you need to also #include <string.h> here. > +#endif > + > #include "basename-lgpl.h" > > #ifndef HAVE_GETPROGNAME /* not Mac OS X, FreeBSD, NetBSD, > OpenBSD >= 5.4, Cygwin */ > @@ -245,6 +250,38 @@ getprogname (void) > } > } > return NULL; > +# elif defined __USLC__ || defined __sysv5__ /* SCO > OpenServer6/UnixWare */ > + char buf[80]; > + int fd; > + sprintf (buf, "/proc/%d/cmdline", (int)getpid()); Casting getpid() to 'int' is fishy. If it is a type shorter than int, you don't need a cast. If it is 'unsigned int', why not use %u instead of %d ? If it is a type larger that 'int', then better cast to 'long' (or 'unsigned long') and use %ld (or %lu) in the format string. > + fd = open (buf, O_RDONLY); > + if (0 <= fd) > + { > + size_t n = read (fd, buf, 79); > + if (n > 0) > + { > + buf[n] = '\0'; /* Guarantee null-termination */ > + char *ret, *progname; ret is only needed further down below. Declare it only at the point when it's needed. > + progname = (char*) strrchr (buf, '/'); You should be relying on the declaration of strrchr, from <string.h>. The cast is then unnecessary. > + if(progname) It's GNU style to add a space after 'if'. > + { > + progname = progname + 1; /* Skip the '/' */ > + } > + else > + { > + progname = buf; > + } Something is wrong with the indentation here. > + ret = malloc (strlen (progname) + 1); > + if (ret) > + { > + strcpy (ret, progname); > + return ret; > + } > + } > + close (fd); > + } > + return "?"; > # else > # error "getprogname module not ported to this OS" > # endif Bruno