Re: notmuch_thread_get_authors
[notmuch-archives.git] / 78 / 83670eafda85fdc7c68af333c50600f1058310
1 Return-Path: <gzjjgod@gmail.com>\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 8F453431FBC\r
6         for <notmuch@notmuchmail.org>; Sat, 21 Nov 2009 19:07:56 -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 FOM2OT-pNV7G for <notmuch@notmuchmail.org>;\r
11         Sat, 21 Nov 2009 19:07:56 -0800 (PST)\r
12 Received: from mail-gx0-f221.google.com (mail-gx0-f221.google.com\r
13         [209.85.217.221])\r
14         by olra.theworths.org (Postfix) with ESMTP id EC1DA431FAE\r
15         for <notmuch@notmuchmail.org>; Sat, 21 Nov 2009 19:07:55 -0800 (PST)\r
16 Received: by gxk21 with SMTP id 21so3933233gxk.10\r
17         for <notmuch@notmuchmail.org>; Sat, 21 Nov 2009 19:07:55 -0800 (PST)\r
18 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;\r
19         h=domainkey-signature:received:received:from:to:cc:subject:date\r
20         :message-id:x-mailer;\r
21         bh=1b4qTuTZy7cuCliveYb0PuCPZtCMfJ9ELOFeMa1N0tc=;\r
22         b=ZRViiUXOIMHjW/QVaVoG5nm0s9DC/4j+tGZ+8UQpy6kb76BC6hbwdcqtzpn3vn0mkQ\r
23         AL/YYm3H7lHKBxATFcrJ0degaFI3Ej13thFm+7620XgZDfhFvnIpH+JwDb2IwOywZiJS\r
24         Va2l2MA1kSqX5WCTXoiHzktc/tGWzPWPoVbpA=\r
25 DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma;\r
26         h=from:to:cc:subject:date:message-id:x-mailer;\r
27         b=hAxsseWffc8HTQR9UXrqgEZhiYZvck6guLr/XCXgl6Ln2q5ELJtCzgYYt+5Rn6ghWU\r
28         AV5vFsgrOpOHDLvFktR+JXGfTYh77dKzq6FcTS+om5Ew1p+LfMYqL+/EGLEK1bF28VRz\r
29         aPCPIIljyQCXE05NphN72DBSXGwEvTQ4n6RUo=\r
30 Received: by 10.150.38.4 with SMTP id l4mr5562259ybl.340.1258859275618;\r
31         Sat, 21 Nov 2009 19:07:55 -0800 (PST)\r
32 Received: from localhost.localdomain ([123.116.120.71])\r
33         by mx.google.com with ESMTPS id 14sm1524526gxk.10.2009.11.21.19.07.51\r
34         (version=TLSv1/SSLv3 cipher=RC4-MD5);\r
35         Sat, 21 Nov 2009 19:07:54 -0800 (PST)\r
36 From: Jjgod Jiang <gzjjgod@gmail.com>\r
37 To: notmuch@notmuchmail.org\r
38 Date: Sun, 22 Nov 2009 11:07:36 +0800\r
39 Message-Id: <1258859256-33197-1-git-send-email-gzjjgod@gmail.com>\r
40 X-Mailer: git-send-email 1.6.4\r
41 Subject: [notmuch] [PATCH] Mac OS X compatibility fixes\r
42 X-BeenThere: notmuch@notmuchmail.org\r
43 X-Mailman-Version: 2.1.12\r
44 Precedence: list\r
45 List-Id: "Use and development of the notmuch mail system."\r
46         <notmuch.notmuchmail.org>\r
47 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
48         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
49 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
50 List-Post: <mailto:notmuch@notmuchmail.org>\r
51 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
52 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
53         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
54 X-List-Received-Date: Sun, 22 Nov 2009 03:07:56 -0000\r
55 \r
56 Add missing GNU extensions strdup() and getline(). The C library\r
57 shipped with Mac OS X does not include them (though it does support\r
58 some GNU extensions when _GNU_SOURCE is defined), so we have to\r
59 add these two. The getline() implementation is a modified version\r
60 of getdelim() from GNU Libc.\r
61 ---\r
62  lib/xutil.c |   99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\r
63  lib/xutil.h |    6 +++\r
64  2 files changed, 105 insertions(+), 0 deletions(-)\r
65 \r
66 diff --git a/lib/xutil.c b/lib/xutil.c\r
67 index 6fa5eb0..805b236 100644\r
68 --- a/lib/xutil.c\r
69 +++ b/lib/xutil.c\r
70 @@ -79,6 +79,105 @@ xstrdup (const char *s)\r
71      return ret;\r
72  }\r
73  \r
74 +#ifdef __APPLE__\r
75 +/* Mac OS X don't have strndup even if _GNU_SOURCE is defined */\r
76 +char *strndup (const char *s, size_t n)\r
77 +{\r
78 +    size_t len = strlen (s);\r
79 +    char *ret;\r
80 +\r
81 +    if (len <= n)\r
82 +       return strdup (s);\r
83 +\r
84 +    ret = malloc(n + 1);\r
85 +    strncpy(ret, s, n);\r
86 +    ret[n] = '\0';\r
87 +    return ret;\r
88 +}\r
89 +\r
90 +/* getline implementation is copied from glibc. */\r
91 +\r
92 +#ifndef SIZE_MAX\r
93 +# define SIZE_MAX ((size_t) -1)\r
94 +#endif\r
95 +#ifndef SSIZE_MAX\r
96 +# define SSIZE_MAX ((ssize_t) (SIZE_MAX / 2))\r
97 +#endif\r
98 +\r
99 +ssize_t getline (char **lineptr, size_t *n, FILE *fp)\r
100 +{\r
101 +    ssize_t result;\r
102 +    size_t cur_len = 0;\r
103 +\r
104 +    if (lineptr == NULL || n == NULL || fp == NULL)\r
105 +    {\r
106 +       errno = EINVAL;\r
107 +       return -1;\r
108 +    }\r
109 +\r
110 +    if (*lineptr == NULL || *n == 0)\r
111 +    {\r
112 +       *n = 120;\r
113 +       *lineptr = (char *) malloc (*n);\r
114 +       if (*lineptr == NULL)\r
115 +       {\r
116 +           result = -1;\r
117 +           goto end;\r
118 +       }\r
119 +    }\r
120 +\r
121 +    for (;;)\r
122 +    {\r
123 +       int i;\r
124 +\r
125 +       i = getc (fp);\r
126 +       if (i == EOF)\r
127 +       {\r
128 +           result = -1;\r
129 +           break;\r
130 +       }\r
131 +\r
132 +       /* Make enough space for len+1 (for final NUL) bytes.  */\r
133 +       if (cur_len + 1 >= *n)\r
134 +       {\r
135 +           size_t needed_max =\r
136 +               SSIZE_MAX < SIZE_MAX ? (size_t) SSIZE_MAX + 1 : SIZE_MAX;\r
137 +           size_t needed = 2 * *n + 1;   /* Be generous. */\r
138 +           char *new_lineptr;\r
139 +\r
140 +           if (needed_max < needed)\r
141 +               needed = needed_max;\r
142 +           if (cur_len + 1 >= needed)\r
143 +           {\r
144 +               result = -1;\r
145 +               goto end;\r
146 +           }\r
147 +\r
148 +           new_lineptr = (char *) realloc (*lineptr, needed);\r
149 +           if (new_lineptr == NULL)\r
150 +           {\r
151 +               result = -1;\r
152 +               goto end;\r
153 +           }\r
154 +\r
155 +           *lineptr = new_lineptr;\r
156 +           *n = needed;\r
157 +       }\r
158 +\r
159 +       (*lineptr)[cur_len] = i;\r
160 +       cur_len++;\r
161 +\r
162 +       if (i == '\n')\r
163 +           break;\r
164 +    }\r
165 +    (*lineptr)[cur_len] = '\0';\r
166 +    result = cur_len ? (ssize_t) cur_len : result;\r
167 +\r
168 +end:\r
169 +    return result;\r
170 +}\r
171 +#endif\r
172 +\r
173  char *\r
174  xstrndup (const char *s, size_t n)\r
175  {\r
176 diff --git a/lib/xutil.h b/lib/xutil.h\r
177 index b973f7d..0b53f7c 100644\r
178 --- a/lib/xutil.h\r
179 +++ b/lib/xutil.h\r
180 @@ -25,6 +25,12 @@\r
181  #include <sys/types.h>\r
182  #include <regex.h>\r
183  \r
184 +#ifdef __APPLE__\r
185 +/* Mac OS X don't have strndup and getline even if _GNU_SOURCE is defined */\r
186 +char *strndup (const char *s, size_t n);\r
187 +ssize_t getline(char **lineptr, size_t *n, FILE *stream);\r
188 +#endif\r
189 +\r
190  /* xutil.c */\r
191  void *\r
192  xcalloc (size_t nmemb, size_t size);\r
193 -- \r
194 1.6.4\r
195 \r