1 Return-Path: <jeff@ocjtech.us>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id CA03B431FC4
\r
6 for <notmuch@notmuchmail.org>; Mon, 23 Nov 2009 05:44:08 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
8 Received: from olra.theworths.org ([127.0.0.1])
\r
9 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
10 with ESMTP id Ob-gCvvJIig4 for <notmuch@notmuchmail.org>;
\r
11 Mon, 23 Nov 2009 05:44:07 -0800 (PST)
\r
12 Received: from mail-yw0-f200.google.com (mail-yw0-f200.google.com
\r
14 by olra.theworths.org (Postfix) with ESMTP id BCC58431FBF
\r
15 for <notmuch@notmuchmail.org>; Mon, 23 Nov 2009 05:44:07 -0800 (PST)
\r
16 Received: by ywh38 with SMTP id 38so4839962ywh.6
\r
17 for <notmuch@notmuchmail.org>; Mon, 23 Nov 2009 05:44:07 -0800 (PST)
\r
18 Received: by 10.150.109.7 with SMTP id h7mr4222931ybc.349.1258983847264;
\r
19 Mon, 23 Nov 2009 05:44:07 -0800 (PST)
\r
20 Received: from lt26923.campus.dmacc.edu ([69.57.47.215])
\r
21 by mx.google.com with ESMTPS id 16sm2067660gxk.3.2009.11.23.05.44.05
\r
22 (version=TLSv1/SSLv3 cipher=RC4-MD5);
\r
23 Mon, 23 Nov 2009 05:44:05 -0800 (PST)
\r
24 Received: from localhost ([127.0.0.1] helo=localhost.localdomain)
\r
25 by lt26923.campus.dmacc.edu with esmtps (TLSv1:AES256-SHA:256)
\r
26 (Exim 4.69) (envelope-from <jeff@ocjtech.us>)
\r
27 id 1NCZD1-0007Hp-Qr; Mon, 23 Nov 2009 07:44:03 -0600
\r
28 From: "Jeffrey C. Ollie" <jeff@ocjtech.us>
\r
29 To: Not Much Mail <notmuch@notmuchmail.org>
\r
30 Date: Mon, 23 Nov 2009 07:43:30 -0600
\r
31 Message-Id: <1258983810-27522-2-git-send-email-jeff@ocjtech.us>
\r
32 X-Mailer: git-send-email 1.6.5.2
\r
33 In-Reply-To: <1258983810-27522-1-git-send-email-jeff@ocjtech.us>
\r
34 References: <87bpiughr3.fsf@yoom.home.cworth.org>
\r
35 <1258983810-27522-1-git-send-email-jeff@ocjtech.us>
\r
36 Subject: [notmuch] [PATCH] Add private implementations of strndup and
\r
38 X-BeenThere: notmuch@notmuchmail.org
\r
39 X-Mailman-Version: 2.1.12
\r
41 List-Id: "Use and development of the notmuch mail system."
\r
42 <notmuch.notmuchmail.org>
\r
43 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
44 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
45 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
46 List-Post: <mailto:notmuch@notmuchmail.org>
\r
47 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
48 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
49 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
50 X-List-Received-Date: Mon, 23 Nov 2009 13:44:09 -0000
\r
52 Add private implementations of strndup and getline for those platforms
\r
53 that don't have them (notably Mac OS X) no matter what preprocessor
\r
56 Signed-off-by: Jeffrey C. Ollie <jeff@ocjtech.us>
\r
58 lib/xutil.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
\r
60 2 files changed, 105 insertions(+), 0 deletions(-)
\r
62 diff --git a/lib/xutil.c b/lib/xutil.c
\r
63 index 6fa5eb0..61467f1 100644
\r
66 @@ -79,6 +79,105 @@ xstrdup (const char *s)
\r
70 +/* Mac OS X don't have strndup even if _GNU_SOURCE is defined */
\r
72 +_notmuch_strndup (const char *s, size_t n)
\r
74 + size_t len = strlen (s);
\r
78 + return strdup (s);
\r
80 + ret = malloc(n + 1);
\r
81 + strncpy(ret, s, n);
\r
86 +/* getline implementation is copied from glibc. */
\r
89 +# define SIZE_MAX ((size_t) -1)
\r
92 +# define SSIZE_MAX ((ssize_t) (SIZE_MAX / 2))
\r
96 +_notmuch_getline (char **lineptr, size_t *n, FILE *fp)
\r
99 + size_t cur_len = 0;
\r
101 + if (lineptr == NULL || n == NULL || fp == NULL)
\r
107 + if (*lineptr == NULL || *n == 0)
\r
110 + *lineptr = (char *) malloc (*n);
\r
111 + if (*lineptr == NULL)
\r
129 + /* Make enough space for len+1 (for final NUL) bytes. */
\r
130 + if (cur_len + 1 >= *n)
\r
132 + size_t needed_max =
\r
133 + SSIZE_MAX < SIZE_MAX ? (size_t) SSIZE_MAX + 1 : SIZE_MAX;
\r
134 + size_t needed = 2 * *n + 1; /* Be generous. */
\r
135 + char *new_lineptr;
\r
137 + if (needed_max < needed)
\r
138 + needed = needed_max;
\r
139 + if (cur_len + 1 >= needed)
\r
145 + new_lineptr = (char *) realloc (*lineptr, needed);
\r
146 + if (new_lineptr == NULL)
\r
152 + *lineptr = new_lineptr;
\r
156 + (*lineptr)[cur_len] = i;
\r
162 + (*lineptr)[cur_len] = '\0';
\r
163 + result = cur_len ? (ssize_t) cur_len : result;
\r
170 xstrndup (const char *s, size_t n)
\r
172 diff --git a/lib/xutil.h b/lib/xutil.h
\r
173 index b973f7d..d13259a 100644
\r
176 @@ -39,6 +39,12 @@ char *
\r
177 xstrdup (const char *s);
\r
180 +_notmuch_strndup (const char *s, size_t n);
\r
183 +_notmuch_getline (char **lineptr, size_t *n, FILE *stream);
\r
186 xstrndup (const char *s, size_t n);
\r