From: Bruno Haible <bruno@clisp.org>
To: Benji Wiebe <benjiwiebe14@gmail.com>
Cc: bug-gnulib@gnu.org
Subject: Re: Port getprogname module to SCO OpenServer
Date: Sat, 03 Oct 2020 16:08:14 +0200 [thread overview]
Message-ID: <32693010.icoaL54Vgk@omega> (raw)
In-Reply-To: <fd7272ba-fc7a-2204-ee0e-d6c8f3be35cd@gmail.com>
[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
next prev parent reply other threads:[~2020-10-03 14:08 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-01 3:30 Port getprogname module to SCO OpenServer Benji Wiebe
2020-10-01 15:59 ` Bruno Haible
[not found] ` <fd7272ba-fc7a-2204-ee0e-d6c8f3be35cd@gmail.com>
2020-10-03 14:08 ` Bruno Haible [this message]
2020-10-07 2:13 ` Benji Wiebe
2020-10-11 19:18 ` Bruno Haible
2020-10-01 18:59 ` Tim Rice
2020-10-02 0:52 ` Benji Wiebe
2020-10-03 13:54 ` Bruno Haible
2020-10-04 0:28 ` Tim Rice
2020-10-04 2:48 ` Bruno Haible
2020-10-06 0:10 ` Tim Rice
2020-10-06 21:21 ` Bruno Haible
2020-10-06 2:23 ` Benji Wiebe
2020-10-06 3:00 ` Tim Rice
2020-10-06 21:16 ` Bruno Haible
2020-10-06 21:47 ` Tim Rice
2020-10-06 22:01 ` Bruno Haible
2020-10-06 22:45 ` Tim Rice
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=32693010.icoaL54Vgk@omega \
--to=bruno@clisp.org \
--cc=benjiwiebe14@gmail.com \
--cc=bug-gnulib@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).