From owner-freebsd-fs Sun Aug 19 2:36:37 2001 Delivered-To: freebsd-fs@freebsd.org Received: from zevs.idi.ntnu.no (zevs.idi.ntnu.no [129.241.110.12]) by hub.freebsd.org (Postfix) with ESMTP id 596B037B40C for ; Sun, 19 Aug 2001 02:36:32 -0700 (PDT) (envelope-from adf@idi.ntnu.no) Received: from idi.ntnu.no (IDENT:1892@vier.idi.ntnu.no [129.241.103.4]) by zevs.idi.ntnu.no (8.9.3/8.9.3) with ESMTP id BAA10850; Sun, 19 Aug 2001 01:24:21 +0200 (MEST) Message-Id: <200108182324.BAA10850@zevs.idi.ntnu.no> X-Mailer: exmh version 2.2 10/02/2000 with version: MH 6.8.3 #1[UCI] To: Josef Karthauser Cc: Dag-Erling Smorgrav , freebsd-fs@FreeBSD.ORG, adf@idi.ntnu.no Subject: Re: parsing problem with /proc/N/status In-reply-to: Your message of "Sat, 18 Aug 2001 14:19:40 BST." <20010818141940.B877@tao.org.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Sun, 19 Aug 2001 01:24:21 +0200 From: Arne Dag Fidjestøl Sender: owner-freebsd-fs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org > > newline). If we have to go down that road, I'd rather just encode > > whitespace and unprintables in octal notation (like ls -B does). Unprintables vary with locales, so octal encoding should probably be limited to ascii-whitespace? > Sounds fair. I don't particularly care, but as it stands it's next > to useless as it's unparsable. Provided that there is a known number of space-seperated fields it is still parsable. See attached program for a lightly-tested example. -adf #include #include #include #include #include #include #define PSTATUS "/proc/curproc/status" /* * return number of characters in progname, or -1 on error. */ int getprognamelen(const char *status, size_t len) { const char *s = status + len; int nspc = 14; /* number of field-seperating-spaces */ for (; s > status && nspc; s--) if (*s == ' ') nspc--; return nspc ? -1 : s - status + 1; } int main() { char buf[1024]; int i,f,sz; f = open(PSTATUS, O_RDONLY); if (f != -1) { sz = read(f, buf, sizeof(buf)); close(f); }else err(1, PSTATUS); i = getprognamelen(buf, sz); if (i != -1) printf("getprogname -> '%.*s' [%d]\n", i, buf, i); else printf("getprogname failed\n"); return 0; } To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-fs" in the body of the message