From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=AWL,BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 306261F4B4 for ; Sat, 3 Oct 2020 14:08:26 +0000 (UTC) Received: from localhost ([::1]:38288 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kOiD3-0003tg-55 for normalperson@yhbt.net; Sat, 03 Oct 2020 10:08:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48418) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kOiCy-0003tY-6V for bug-gnulib@gnu.org; Sat, 03 Oct 2020 10:08:20 -0400 Received: from mo4-p01-ob.smtp.rzone.de ([81.169.146.166]:32523) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kOiCw-0003Zt-18 for bug-gnulib@gnu.org; Sat, 03 Oct 2020 10:08:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1601734095; s=strato-dkim-0002; d=clisp.org; h=References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=4CqcphRN1ORr7j4F9PANXwbv2YXc3J07kPDzehfiho4=; b=LtkwhvJdIX+IY9dDehAa3HN/mvyZST0jzfwZuWHFjdOlkKHyQ9TAn/6UhV+1na1Tw2 cchPs1fKCeS15eFWq98ZWoobos+uy35UswgQSYnhkmVydTtzsIk6kE2dmcHBmVsoFuIE 8kgR+h6wdCYzwewrdNIR5Rg9xD7ivtA4HdVnUo1b3s5/mggvDj4oEwHS+/LKDJl+C4ED 8zYrcDj+uQ+rJEh9ERvqA2l8x6gHjo6jlStT3fggbmO/K7+jsbP3Xn3NVvTsm/9WLEJ4 LRi1faDbAJWIyIRDQYM0NgvEscFYMXXO1dSQkjtdPxDao5/gEe639zW0dAnHdBqwCKBp 4IJw== X-RZG-AUTH: ":Ln4Re0+Ic/6oZXR1YgKryK8brlshOcZlIWs+iCP5vnk6shH+AHjwLuWOGaf0yJVW" X-RZG-CLASS-ID: mo00 Received: from bruno.haible.de by smtp.strato.de (RZmta 47.2.1 DYNA|AUTH) with ESMTPSA id R01daaw93E8E45x (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (curve X9_62_prime256v1 with 256 ECDH bits, eq. 3072 bits RSA)) (Client did not present a certificate); Sat, 3 Oct 2020 16:08:14 +0200 (CEST) From: Bruno Haible To: Benji Wiebe Subject: Re: Port getprogname module to SCO OpenServer Date: Sat, 03 Oct 2020 16:08:14 +0200 Message-ID: <32693010.icoaL54Vgk@omega> User-Agent: KMail/5.1.3 (Linux/4.4.0-189-generic; KDE/5.18.0; x86_64; ; ) In-Reply-To: References: <4175309.xE8b4x1JMc@omega> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Received-SPF: none client-ip=81.169.146.166; envelope-from=bruno@clisp.org; helo=mo4-p01-ob.smtp.rzone.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/03 10:08:15 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, NICE_REPLY_A=-0.252, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: bug-gnulib@gnu.org Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: "bug-gnulib" [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 > #endif > > +#if defined __USLC__ || defined __sysv5__ Please use either #ifdef _SCO_DS or #ifdef __SCO_VERSION__, as discussed in the other mail. > +# include > +# include Now that you use strrchr(), you need to also #include 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 . 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