comparison src/xrdb.c @ 109687:d6c4fa12ba52

Cleanup xrdb.c. * src/xrdb.c: Remove include guard. Remove DECLARE_GETPWUID_WITH_UID_T conditional it had no effect. Remove #if 0 code. Replace malloc->xmalloc, free->xfree, realloc->xrealloc instead of using #defines.
author Dan Nicolaescu <dann@ics.uci.edu>
date Sun, 08 Aug 2010 13:16:48 -0700
parents 228a5fa4eda0
children 64732fa6188a
comparison
equal deleted inserted replaced
109686:111f90199914 109687:d6c4fa12ba52
18 GNU General Public License for more details. 18 GNU General Public License for more details.
19 19
20 You should have received a copy of the GNU General Public License 20 You should have received a copy of the GNU General Public License
21 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ 21 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
22 22
23 #ifdef emacs
24 #include <config.h> 23 #include <config.h>
25 #endif
26 24
27 #ifdef HAVE_UNISTD_H 25 #ifdef HAVE_UNISTD_H
28 #include <unistd.h> 26 #include <unistd.h>
29 #endif 27 #endif
30 28
50 48
51 #include "lisp.h" 49 #include "lisp.h"
52 50
53 extern char *getenv (const char *); 51 extern char *getenv (const char *);
54 52
55 /* This does cause trouble on AIX. I'm going to take the comment at
56 face value. */
57 #if 0
58 extern short getuid (); /* If this causes portability problems,
59 I think we should just delete it; it'll
60 default to `int' anyway. */
61 #endif
62
63 #ifdef DECLARE_GETPWUID_WITH_UID_T
64 extern struct passwd *getpwuid (uid_t); 53 extern struct passwd *getpwuid (uid_t);
65 extern struct passwd *getpwnam (const char *); 54 extern struct passwd *getpwnam (const char *);
66 #else
67 extern struct passwd *getpwuid (uid_t);
68 extern struct passwd *getpwnam (const char *);
69 #endif
70 55
71 extern char *get_system_name (void); 56 extern char *get_system_name (void);
72
73 /* Make sure not to #include anything after these definitions. Let's
74 not step on anyone's prototypes. */
75 #ifdef emacs
76 /* darwin.h may have already defined these. */
77 #undef malloc
78 #undef realloc
79 #undef free
80 #define malloc xmalloc
81 #define realloc xrealloc
82 #define free xfree
83 #endif
84 57
85 char *x_get_string_resource (XrmDatabase rdb, const char *name, 58 char *x_get_string_resource (XrmDatabase rdb, const char *name,
86 const char *class); 59 const char *class);
87 static int file_p (const char *filename); 60 static int file_p (const char *filename);
88 61
112 85
113 result = x_get_string_resource (db, full_name, full_class); 86 result = x_get_string_resource (db, full_name, full_class);
114 87
115 if (result) 88 if (result)
116 { 89 {
117 char *copy = (char *) malloc (strlen (result) + 1); 90 char *copy = (char *) xmalloc (strlen (result) + 1);
118 strcpy (copy, result); 91 strcpy (copy, result);
119 return copy; 92 return copy;
120 } 93 }
121 else 94 else
122 return 0; 95 return 0;
157 magic_file_p (const char *string, int string_len, const char *class, const char *escaped_suffix, const char *suffix) 130 magic_file_p (const char *string, int string_len, const char *class, const char *escaped_suffix, const char *suffix)
158 { 131 {
159 char *lang = getenv ("LANG"); 132 char *lang = getenv ("LANG");
160 133
161 int path_size = 100; 134 int path_size = 100;
162 char *path = (char *) malloc (path_size); 135 char *path = (char *) xmalloc (path_size);
163 int path_len = 0; 136 int path_len = 0;
164 137
165 const char *p = string; 138 const char *p = string;
166 139
167 while (p < string + string_len) 140 while (p < string + string_len)
208 181
209 case 'L': 182 case 'L':
210 case 'l': 183 case 'l':
211 if (! lang) 184 if (! lang)
212 { 185 {
213 free (path); 186 xfree (path);
214 return NULL; 187 return NULL;
215 } 188 }
216 189
217 next = lang; 190 next = lang;
218 next_len = strlen (next); 191 next_len = strlen (next);
219 break; 192 break;
220 193
221 case 't': 194 case 't':
222 case 'c': 195 case 'c':
223 free (path); 196 xfree (path);
224 return NULL; 197 return NULL;
225 } 198 }
226 } 199 }
227 else 200 else
228 next = p, next_len = 1; 201 next = p, next_len = 1;
229 202
230 /* Do we have room for this component followed by a '\0' ? */ 203 /* Do we have room for this component followed by a '\0' ? */
231 if (path_len + next_len + 1 > path_size) 204 if (path_len + next_len + 1 > path_size)
232 { 205 {
233 path_size = (path_len + next_len + 1) * 2; 206 path_size = (path_len + next_len + 1) * 2;
234 path = (char *) realloc (path, path_size); 207 path = (char *) xrealloc (path, path_size);
235 } 208 }
236 209
237 memcpy (path + path_len, next, next_len); 210 memcpy (path + path_len, next, next_len);
238 path_len += next_len; 211 path_len += next_len;
239 212
255 int suffix_len = strlen (suffix); 228 int suffix_len = strlen (suffix);
256 229
257 if (path_len + suffix_len + 1 > path_size) 230 if (path_len + suffix_len + 1 > path_size)
258 { 231 {
259 path_size = (path_len + suffix_len + 1); 232 path_size = (path_len + suffix_len + 1);
260 path = (char *) realloc (path, path_size); 233 path = (char *) xrealloc (path, path_size);
261 } 234 }
262 235
263 memcpy (path + path_len, suffix, suffix_len); 236 memcpy (path + path_len, suffix, suffix_len);
264 path_len += suffix_len; 237 path_len += suffix_len;
265 } 238 }
266 239
267 path[path_len] = '\0'; 240 path[path_len] = '\0';
268 241
269 if (! file_p (path)) 242 if (! file_p (path))
270 { 243 {
271 free (path); 244 xfree (path);
272 return NULL; 245 return NULL;
273 } 246 }
274 247
275 return path; 248 return path;
276 } 249 }
296 } 269 }
297 270
298 if (ptr == NULL) 271 if (ptr == NULL)
299 return xstrdup ("/"); 272 return xstrdup ("/");
300 273
301 copy = (char *) malloc (strlen (ptr) + 2); 274 copy = (char *) xmalloc (strlen (ptr) + 2);
302 strcpy (copy, ptr); 275 strcpy (copy, ptr);
303 strcat (copy, "/"); 276 strcat (copy, "/");
304 277
305 return copy; 278 return copy;
306 } 279 }
368 341
369 path = search_magic_path (path, class, 0, 0); 342 path = search_magic_path (path, class, 0, 0);
370 if (path) 343 if (path)
371 { 344 {
372 db = XrmGetFileDatabase (path); 345 db = XrmGetFileDatabase (path);
373 free (path); 346 xfree (path);
374 } 347 }
375 348
376 return db; 349 return db;
377 } 350 }
378 351
407 || (free_it = gethomedir (), 380 || (free_it = gethomedir (),
408 ((file = search_magic_path (free_it, class, "%L/%N", 0)) 381 ((file = search_magic_path (free_it, class, "%L/%N", 0))
409 || (file = search_magic_path (free_it, class, "%N", 0))))) 382 || (file = search_magic_path (free_it, class, "%N", 0)))))
410 { 383 {
411 XrmDatabase db = XrmGetFileDatabase (file); 384 XrmDatabase db = XrmGetFileDatabase (file);
412 free (file); 385 xfree (file);
413 free (free_it); 386 xfree (free_it);
414 return db; 387 return db;
415 } 388 }
416 389
417 free (free_it); 390 xfree (free_it);
418 return NULL; 391 return NULL;
419 } 392 }
420 393
421 394
422 static XrmDatabase 395 static XrmDatabase
437 { 410 {
438 char *home; 411 char *home;
439 char *xdefault; 412 char *xdefault;
440 413
441 home = gethomedir (); 414 home = gethomedir ();
442 xdefault = (char *) malloc (strlen (home) + sizeof (".Xdefaults")); 415 xdefault = (char *) xmalloc (strlen (home) + sizeof (".Xdefaults"));
443 strcpy (xdefault, home); 416 strcpy (xdefault, home);
444 strcat (xdefault, ".Xdefaults"); 417 strcat (xdefault, ".Xdefaults");
445 db = XrmGetFileDatabase (xdefault); 418 db = XrmGetFileDatabase (xdefault);
446 free (home); 419 xfree (home);
447 free (xdefault); 420 xfree (xdefault);
448 } 421 }
449 422
450 #ifdef HAVE_XSCREENRESOURCESTRING 423 #ifdef HAVE_XSCREENRESOURCESTRING
451 /* Get the screen-specific resources too. */ 424 /* Get the screen-specific resources too. */
452 xdefs = XScreenResourceString (DefaultScreenOfDisplay (display)); 425 xdefs = XScreenResourceString (DefaultScreenOfDisplay (display));
469 442
470 if ((p = getenv ("XENVIRONMENT")) == NULL) 443 if ((p = getenv ("XENVIRONMENT")) == NULL)
471 { 444 {
472 home = gethomedir (); 445 home = gethomedir ();
473 host = get_system_name (); 446 host = get_system_name ();
474 path = (char *) malloc (strlen (home) 447 path = (char *) xmalloc (strlen (home)
475 + sizeof (".Xdefaults-") 448 + sizeof (".Xdefaults-")
476 + strlen (host)); 449 + strlen (host));
477 sprintf (path, "%s%s%s", home, ".Xdefaults-", host); 450 sprintf (path, "%s%s%s", home, ".Xdefaults-", host);
478 p = path; 451 p = path;
479 } 452 }
480 453
481 db = XrmGetFileDatabase (p); 454 db = XrmGetFileDatabase (p);
482 455
483 free (path); 456 xfree (path);
484 free (home); 457 xfree (home);
485 458
486 return db; 459 return db;
487 } 460 }
488 461
489 /* External interface. */ 462 /* External interface. */
584 557
585 user_database = get_user_db (display); 558 user_database = get_user_db (display);
586 559
587 /* Figure out what the "customization string" is, so we can use it 560 /* Figure out what the "customization string" is, so we can use it
588 to decode paths. */ 561 to decode paths. */
589 free (x_customization_string); 562 xfree (x_customization_string);
590 x_customization_string 563 x_customization_string
591 = x_get_customization_string (user_database, myname, myclass); 564 = x_get_customization_string (user_database, myname, myclass);
592 565
593 /* Get application system defaults */ 566 /* Get application system defaults */
594 db = get_system_app (myclass); 567 db = get_system_app (myclass);