Date: Thu, 5 Aug 1999 19:54:35 -0400 (EDT) From: James Howard <howardjp@wam.umd.edu> To: FreeBSD-gnats-submit@freebsd.org Subject: docs/12994: Update to getopt.3 to agree with style.9 Message-ID: <199908052354.TAA17724@rac9.wam.umd.edu>
next in thread | raw e-mail | index | archive | help
>Number: 12994 >Category: docs >Synopsis: Update to getopt.3 to agree with style.9 >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-doc >State: open >Quarter: >Keywords: >Date-Required: >Class: doc-bug >Submitter-Id: current-users >Arrival-Date: Thu Aug 5 17:00:06 PDT 1999 >Closed-Date: >Last-Modified: >Originator: James Howard >Release: FreeBSD 3.2-STABLE i386 >Organization: University of Maryland >Environment: FreeBSD byzantine.student.umd.edu 3.2-STABLE FreeBSD 3.2-STABLE #4: Thu Jun 17 18:40:41 GMT 1999 howardjp@byzantine.student.umd.edu:/usr/src/sys/compile/BYZANTINE i386 >Description: Getopt(3) stated that the proper way to handle converting a number in a command line to a usable int was via atoi(3). Style(9) says you should use strtol(3). Apply the diff to getopt.3 in /usr/src/lib/libc/stdlib/ to synchronise it with style(9). >How-To-Repeat: man 3 getopt man style >Fix: *** getopt.3.orig Thu Aug 5 19:31:46 1999 --- getopt.3 Thu Aug 5 19:41:08 1999 *************** *** 245,251 **** The following code fragment works in most cases. .Bd -literal -offset indent int length; ! char *p; while ((ch = getopt(argc, argv, "0123456789")) != -1) switch (ch) { --- 245,251 ---- The following code fragment works in most cases. .Bd -literal -offset indent int length; ! char *p, *ep; while ((ch = getopt(argc, argv, "0123456789")) != -1) switch (ch) { *************** *** 253,261 **** case '5': case '6': case '7': case '8': case '9': p = argv[optind - 1]; if (p[0] == '-' && p[1] == ch && !p[2]) ! length = atoi(++p); else ! length = atoi(argv[optind] + 1); break; } .Ed --- 253,263 ---- case '5': case '6': case '7': case '8': case '9': p = argv[optind - 1]; if (p[0] == '-' && p[1] == ch && !p[2]) ! length = strtol(++p, &ep, 10); else ! length = strtol(argv[optind] + 1, &ep, 10); ! if (length <= 0 || *ep != '\e0') ! err("illegal number -- %s", optarg); break; } .Ed >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-doc" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199908052354.TAA17724>