| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#include "makeint.h" |
| 18 |
#include "filedef.h" |
| 19 |
#include "dep.h" |
| 20 |
#include "debug.h" |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
#include <stdarg.h> |
| 25 |
|
| 26 |
#ifdef WINDOWS32 |
| 27 |
# include <windows.h> |
| 28 |
# include <io.h> |
| 29 |
#endif |
| 30 |
|
| 31 |
#ifdef HAVE_FCNTL_H |
| 32 |
# include <fcntl.h> |
| 33 |
#else |
| 34 |
# include <sys/file.h> |
| 35 |
#endif |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
int |
| 42 |
alpha_compare (const void *v1, const void *v2) |
| 43 |
{ |
| 44 |
const char *s1 = *((char **)v1); |
| 45 |
const char *s2 = *((char **)v2); |
| 46 |
|
| 47 |
if (*s1 != *s2) |
| 48 |
return *s1 - *s2; |
| 49 |
return strcmp (s1, s2); |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
void |
| 57 |
collapse_continuations (char *line) |
| 58 |
{ |
| 59 |
char *out = line; |
| 60 |
char *in = line; |
| 61 |
char *q; |
| 62 |
|
| 63 |
q = strchr(in, '\n'); |
| 64 |
if (q == 0) |
| 65 |
return; |
| 66 |
|
| 67 |
do |
| 68 |
{ |
| 69 |
char *p = q; |
| 70 |
int i; |
| 71 |
size_t out_line_length; |
| 72 |
|
| 73 |
if (q > line && q[-1] == '\\') |
| 74 |
{ |
| 75 |
|
| 76 |
i = -2; |
| 77 |
while (&p[i] >= line && p[i] == '\\') |
| 78 |
--i; |
| 79 |
++i; |
| 80 |
} |
| 81 |
else |
| 82 |
i = 0; |
| 83 |
|
| 84 |
|
| 85 |
out_line_length = (p - in) + i - i/2; |
| 86 |
if (out != in) |
| 87 |
memmove (out, in, out_line_length); |
| 88 |
out += out_line_length; |
| 89 |
|
| 90 |
|
| 91 |
in = q + 1; |
| 92 |
|
| 93 |
if (i & 1) |
| 94 |
{ |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
while (ISBLANK (*in)) |
| 101 |
++in; |
| 102 |
if (! posix_pedantic) |
| 103 |
while (out > line && ISBLANK (out[-1])) |
| 104 |
--out; |
| 105 |
*out++ = ' '; |
| 106 |
} |
| 107 |
else |
| 108 |
{ |
| 109 |
|
| 110 |
*out++ = '\n'; |
| 111 |
} |
| 112 |
|
| 113 |
q = strchr(in, '\n'); |
| 114 |
} |
| 115 |
while (q); |
| 116 |
|
| 117 |
memmove(out, in, strlen(in) + 1); |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
void |
| 123 |
print_spaces (unsigned int n) |
| 124 |
{ |
| 125 |
while (n-- > 0) |
| 126 |
putchar (' '); |
| 127 |
} |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
const char * |
| 134 |
concat (unsigned int num, ...) |
| 135 |
{ |
| 136 |
static size_t rlen = 0; |
| 137 |
static char *result = NULL; |
| 138 |
size_t ri = 0; |
| 139 |
va_list args; |
| 140 |
|
| 141 |
va_start (args, num); |
| 142 |
|
| 143 |
while (num-- > 0) |
| 144 |
{ |
| 145 |
const char *s = va_arg (args, const char *); |
| 146 |
size_t l = xstrlen (s); |
| 147 |
|
| 148 |
if (l == 0) |
| 149 |
continue; |
| 150 |
|
| 151 |
if (ri + l > rlen) |
| 152 |
{ |
| 153 |
rlen = ((rlen ? rlen : 60) + l) * 2; |
| 154 |
result = xrealloc (result, rlen); |
| 155 |
} |
| 156 |
|
| 157 |
memcpy (result + ri, s, l); |
| 158 |
ri += l; |
| 159 |
} |
| 160 |
|
| 161 |
va_end (args); |
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
if (ri == rlen) |
| 166 |
{ |
| 167 |
rlen = (rlen ? rlen : 60) * 2; |
| 168 |
result = xrealloc (result, rlen); |
| 169 |
} |
| 170 |
|
| 171 |
result[ri] = '\0'; |
| 172 |
|
| 173 |
return result; |
| 174 |
} |
| 175 |
|
| 176 |
#ifndef HAVE_MEMRCHR |
| 177 |
void * |
| 178 |
memrchr(const void* str, int ch, size_t len) |
| 179 |
{ |
| 180 |
const char* sp = str; |
| 181 |
const char* cp = sp; |
| 182 |
|
| 183 |
if (len == 0) |
| 184 |
return NULL; |
| 185 |
|
| 186 |
cp += len - 1; |
| 187 |
|
| 188 |
while (cp[0] != ch) |
| 189 |
{ |
| 190 |
if (cp == sp) |
| 191 |
return NULL; |
| 192 |
--cp; |
| 193 |
} |
| 194 |
|
| 195 |
return (void*)cp; |
| 196 |
} |
| 197 |
#endif |
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
char * |
| 208 |
lindex (const char *s, const char *limit, int c) |
| 209 |
{ |
| 210 |
while (s < limit) |
| 211 |
if (*s++ == c) |
| 212 |
return (char *)(s - 1); |
| 213 |
|
| 214 |
return 0; |
| 215 |
} |
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
char * |
| 220 |
end_of_token (const char *s) |
| 221 |
{ |
| 222 |
END_OF_TOKEN (s); |
| 223 |
return (char *)s; |
| 224 |
} |
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
char * |
| 229 |
next_token (const char *s) |
| 230 |
{ |
| 231 |
NEXT_TOKEN (s); |
| 232 |
return (char *)s; |
| 233 |
} |
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
char * |
| 240 |
find_next_token (const char **ptr, size_t *lengthptr) |
| 241 |
{ |
| 242 |
const char *p = next_token (*ptr); |
| 243 |
|
| 244 |
if (*p == '\0') |
| 245 |
return 0; |
| 246 |
|
| 247 |
*ptr = end_of_token (p); |
| 248 |
if (lengthptr != 0) |
| 249 |
*lengthptr = *ptr - p; |
| 250 |
|
| 251 |
return (char *)p; |
| 252 |
} |
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
ssize_t |
| 257 |
writebuf (int fd, const void *buffer, size_t len) |
| 258 |
{ |
| 259 |
const char *msg = buffer; |
| 260 |
size_t l = len; |
| 261 |
while (l) |
| 262 |
{ |
| 263 |
ssize_t r; |
| 264 |
|
| 265 |
EINTRLOOP (r, write (fd, msg, l)); |
| 266 |
if (r < 0) |
| 267 |
return r; |
| 268 |
|
| 269 |
l -= r; |
| 270 |
msg += r; |
| 271 |
} |
| 272 |
|
| 273 |
return (ssize_t)len; |
| 274 |
} |
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
ssize_t |
| 280 |
readbuf (int fd, void *buffer, size_t len) |
| 281 |
{ |
| 282 |
char *msg = buffer; |
| 283 |
while (len) |
| 284 |
{ |
| 285 |
ssize_t r; |
| 286 |
|
| 287 |
EINTRLOOP (r, read (fd, msg, len)); |
| 288 |
if (r < 0) |
| 289 |
return r; |
| 290 |
if (r == 0) |
| 291 |
break; |
| 292 |
|
| 293 |
len -= r; |
| 294 |
msg += r; |
| 295 |
} |
| 296 |
|
| 297 |
return (ssize_t)(msg - (char*)buffer); |
| 298 |
} |
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
struct dep * |
| 304 |
copy_dep_chain (const struct dep *d) |
| 305 |
{ |
| 306 |
struct dep *firstnew = 0; |
| 307 |
struct dep *lastnew = 0; |
| 308 |
|
| 309 |
while (d != 0) |
| 310 |
{ |
| 311 |
struct dep *c = xmalloc (sizeof (struct dep)); |
| 312 |
memcpy (c, d, sizeof (struct dep)); |
| 313 |
|
| 314 |
if (c->need_2nd_expansion) |
| 315 |
c->name = xstrdup (c->name); |
| 316 |
|
| 317 |
c->next = 0; |
| 318 |
if (firstnew == 0) |
| 319 |
firstnew = lastnew = c; |
| 320 |
else |
| 321 |
lastnew = lastnew->next = c; |
| 322 |
|
| 323 |
d = d->next; |
| 324 |
} |
| 325 |
|
| 326 |
return firstnew; |
| 327 |
} |
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
void |
| 333 |
free_ns_chain (struct nameseq *ns) |
| 334 |
{ |
| 335 |
while (ns != 0) |
| 336 |
{ |
| 337 |
struct nameseq *t = ns; |
| 338 |
ns = ns->next; |
| 339 |
free_ns (t); |
| 340 |
} |
| 341 |
} |
| 342 |
|
| 343 |
|
| 344 |
#ifdef MAKE_MAINTAINER_MODE |
| 345 |
|
| 346 |
void |
| 347 |
spin (const char* type) |
| 348 |
{ |
| 349 |
char filenm[256]; |
| 350 |
struct stat dummy; |
| 351 |
|
| 352 |
sprintf (filenm, ".make-spin-%s", type); |
| 353 |
|
| 354 |
if (stat (filenm, &dummy) == 0) |
| 355 |
{ |
| 356 |
fprintf (stderr, "SPIN on %s\n", filenm); |
| 357 |
do |
| 358 |
#ifdef WINDOWS32 |
| 359 |
Sleep (1000); |
| 360 |
#else |
| 361 |
sleep (1); |
| 362 |
#endif |
| 363 |
while (stat (filenm, &dummy) == 0); |
| 364 |
} |
| 365 |
} |
| 366 |
|
| 367 |
#endif |
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
#ifndef HAVE_STDLIB_H |
| 374 |
# ifdef HAVE_MKSTEMP |
| 375 |
int mkstemp (char *template); |
| 376 |
# else |
| 377 |
char *mktemp (char *template); |
| 378 |
# endif |
| 379 |
#endif |
| 380 |
|
| 381 |
#ifndef HAVE_UMASK |
| 382 |
mode_t |
| 383 |
umask (mode_t mask) |
| 384 |
{ |
| 385 |
return 0; |
| 386 |
} |
| 387 |
#endif |
| 388 |
|
| 389 |
FILE * |
| 390 |
get_tmpfile (char **name, const char *template) |
| 391 |
{ |
| 392 |
FILE *file; |
| 393 |
#ifdef HAVE_FDOPEN |
| 394 |
int fd; |
| 395 |
#endif |
| 396 |
|
| 397 |
|
| 398 |
mode_t mask = umask (0077); |
| 399 |
|
| 400 |
#if defined(HAVE_MKSTEMP) || defined(HAVE_MKTEMP) |
| 401 |
# define TEMPLATE_LEN strlen (template) |
| 402 |
#else |
| 403 |
# define TEMPLATE_LEN L_tmpnam |
| 404 |
#endif |
| 405 |
*name = xmalloc (TEMPLATE_LEN + 1); |
| 406 |
strcpy (*name, template); |
| 407 |
|
| 408 |
#if defined(HAVE_MKSTEMP) && defined(HAVE_FDOPEN) |
| 409 |
|
| 410 |
EINTRLOOP (fd, mkstemp (*name)); |
| 411 |
if (fd == -1) |
| 412 |
file = NULL; |
| 413 |
else |
| 414 |
file = fdopen (fd, "w"); |
| 415 |
#else |
| 416 |
# ifdef HAVE_MKTEMP |
| 417 |
(void) mktemp (*name); |
| 418 |
# else |
| 419 |
(void) tmpnam (*name); |
| 420 |
# endif |
| 421 |
|
| 422 |
# ifdef HAVE_FDOPEN |
| 423 |
|
| 424 |
EINTRLOOP (fd, open (*name, O_CREAT|O_EXCL|O_WRONLY, 0600)); |
| 425 |
if (fd == -1) |
| 426 |
return 0; |
| 427 |
file = fdopen (fd, "w"); |
| 428 |
# else |
| 429 |
|
| 430 |
file = fopen (*name, "w"); |
| 431 |
# endif |
| 432 |
#endif |
| 433 |
|
| 434 |
umask (mask); |
| 435 |
|
| 436 |
return file; |
| 437 |
} |
| 438 |
|
| 439 |
|
| 440 |
#if !HAVE_STRCASECMP && !HAVE_STRICMP && !HAVE_STRCMPI |
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
int |
| 445 |
strcasecmp (const char *s1, const char *s2) |
| 446 |
{ |
| 447 |
while (1) |
| 448 |
{ |
| 449 |
int c1 = (int) *(s1++); |
| 450 |
int c2 = (int) *(s2++); |
| 451 |
|
| 452 |
if (isalpha (c1)) |
| 453 |
c1 = tolower (c1); |
| 454 |
if (isalpha (c2)) |
| 455 |
c2 = tolower (c2); |
| 456 |
|
| 457 |
if (c1 != '\0' && c1 == c2) |
| 458 |
continue; |
| 459 |
|
| 460 |
return (c1 - c2); |
| 461 |
} |
| 462 |
} |
| 463 |
#endif |
| 464 |
|
| 465 |
#if !HAVE_STRNCASECMP && !HAVE_STRNICMP && !HAVE_STRNCMPI |
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
int |
| 470 |
strncasecmp (const char *s1, const char *s2, int n) |
| 471 |
{ |
| 472 |
while (n-- > 0) |
| 473 |
{ |
| 474 |
int c1 = (int) *(s1++); |
| 475 |
int c2 = (int) *(s2++); |
| 476 |
|
| 477 |
if (isalpha (c1)) |
| 478 |
c1 = tolower (c1); |
| 479 |
if (isalpha (c2)) |
| 480 |
c2 = tolower (c2); |
| 481 |
|
| 482 |
if (c1 != '\0' && c1 == c2) |
| 483 |
continue; |
| 484 |
|
| 485 |
return (c1 - c2); |
| 486 |
} |
| 487 |
|
| 488 |
return 0; |
| 489 |
} |
| 490 |
#endif |
| 491 |
|
| 492 |
#ifdef GETLOADAVG_PRIVILEGED |
| 493 |
|
| 494 |
#ifdef POSIX |
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
#undef HAVE_SETREUID |
| 503 |
#undef HAVE_SETREGID |
| 504 |
|
| 505 |
#else |
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
#undef HAVE_SETEUID |
| 513 |
#undef HAVE_SETEGID |
| 514 |
|
| 515 |
#endif |
| 516 |
|
| 517 |
#ifndef HAVE_UNISTD_H |
| 518 |
extern int getuid (), getgid (), geteuid (), getegid (); |
| 519 |
extern int setuid (), setgid (); |
| 520 |
#ifdef HAVE_SETEUID |
| 521 |
extern int seteuid (); |
| 522 |
#else |
| 523 |
#ifdef HAVE_SETREUID |
| 524 |
extern int setreuid (); |
| 525 |
#endif |
| 526 |
#endif |
| 527 |
#ifdef HAVE_SETEGID |
| 528 |
extern int setegid (); |
| 529 |
#else |
| 530 |
#ifdef HAVE_SETREGID |
| 531 |
extern int setregid (); |
| 532 |
#endif |
| 533 |
#endif |
| 534 |
#endif |
| 535 |
|
| 536 |
|
| 537 |
static int user_uid = -1, user_gid = -1, make_uid = -1, make_gid = -1; |
| 538 |
#define access_inited (user_uid != -1) |
| 539 |
static enum { make, user } current_access; |
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
static void |
| 545 |
log_access (const char *flavor) |
| 546 |
{ |
| 547 |
if (! ISDB (DB_JOBS)) |
| 548 |
return; |
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
fprintf (stderr, _("%s: user %lu (real %lu), group %lu (real %lu)\n"), |
| 555 |
flavor, (unsigned long) geteuid (), (unsigned long) getuid (), |
| 556 |
(unsigned long) getegid (), (unsigned long) getgid ()); |
| 557 |
fflush (stderr); |
| 558 |
} |
| 559 |
|
| 560 |
|
| 561 |
static void |
| 562 |
init_access (void) |
| 563 |
{ |
| 564 |
#ifndef VMS |
| 565 |
user_uid = getuid (); |
| 566 |
user_gid = getgid (); |
| 567 |
|
| 568 |
make_uid = geteuid (); |
| 569 |
make_gid = getegid (); |
| 570 |
|
| 571 |
|
| 572 |
if (user_uid == -1 || user_gid == -1 || make_uid == -1 || make_gid == -1) |
| 573 |
pfatal_with_name ("get{e}[gu]id"); |
| 574 |
|
| 575 |
log_access (_("Initialized access")); |
| 576 |
|
| 577 |
current_access = make; |
| 578 |
#endif |
| 579 |
} |
| 580 |
|
| 581 |
#endif |
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
void |
| 586 |
user_access (void) |
| 587 |
{ |
| 588 |
#ifdef GETLOADAVG_PRIVILEGED |
| 589 |
|
| 590 |
if (!access_inited) |
| 591 |
init_access (); |
| 592 |
|
| 593 |
if (current_access == user) |
| 594 |
return; |
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
#ifdef HAVE_SETEUID |
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
if (seteuid (user_uid) < 0) |
| 607 |
pfatal_with_name ("user_access: seteuid"); |
| 608 |
|
| 609 |
#else |
| 610 |
|
| 611 |
#ifndef HAVE_SETREUID |
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
if (setuid (user_uid) < 0) |
| 622 |
pfatal_with_name ("user_access: setuid"); |
| 623 |
|
| 624 |
#else |
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
if (setreuid (make_uid, user_uid) < 0) |
| 634 |
pfatal_with_name ("user_access: setreuid"); |
| 635 |
|
| 636 |
#endif |
| 637 |
#endif |
| 638 |
|
| 639 |
#ifdef HAVE_SETEGID |
| 640 |
if (setegid (user_gid) < 0) |
| 641 |
pfatal_with_name ("user_access: setegid"); |
| 642 |
#else |
| 643 |
#ifndef HAVE_SETREGID |
| 644 |
if (setgid (user_gid) < 0) |
| 645 |
pfatal_with_name ("user_access: setgid"); |
| 646 |
#else |
| 647 |
if (setregid (make_gid, user_gid) < 0) |
| 648 |
pfatal_with_name ("user_access: setregid"); |
| 649 |
#endif |
| 650 |
#endif |
| 651 |
|
| 652 |
current_access = user; |
| 653 |
|
| 654 |
log_access (_("User access")); |
| 655 |
|
| 656 |
#endif |
| 657 |
} |
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
void |
| 662 |
make_access (void) |
| 663 |
{ |
| 664 |
#ifdef GETLOADAVG_PRIVILEGED |
| 665 |
|
| 666 |
if (!access_inited) |
| 667 |
init_access (); |
| 668 |
|
| 669 |
if (current_access == make) |
| 670 |
return; |
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
#ifdef HAVE_SETEUID |
| 675 |
if (seteuid (make_uid) < 0) |
| 676 |
pfatal_with_name ("make_access: seteuid"); |
| 677 |
#else |
| 678 |
#ifndef HAVE_SETREUID |
| 679 |
if (setuid (make_uid) < 0) |
| 680 |
pfatal_with_name ("make_access: setuid"); |
| 681 |
#else |
| 682 |
if (setreuid (user_uid, make_uid) < 0) |
| 683 |
pfatal_with_name ("make_access: setreuid"); |
| 684 |
#endif |
| 685 |
#endif |
| 686 |
|
| 687 |
#ifdef HAVE_SETEGID |
| 688 |
if (setegid (make_gid) < 0) |
| 689 |
pfatal_with_name ("make_access: setegid"); |
| 690 |
#else |
| 691 |
#ifndef HAVE_SETREGID |
| 692 |
if (setgid (make_gid) < 0) |
| 693 |
pfatal_with_name ("make_access: setgid"); |
| 694 |
#else |
| 695 |
if (setregid (user_gid, make_gid) < 0) |
| 696 |
pfatal_with_name ("make_access: setregid"); |
| 697 |
#endif |
| 698 |
#endif |
| 699 |
|
| 700 |
current_access = make; |
| 701 |
|
| 702 |
log_access (_("Make access")); |
| 703 |
|
| 704 |
#endif |
| 705 |
} |
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
void |
| 710 |
child_access (void) |
| 711 |
{ |
| 712 |
#ifdef GETLOADAVG_PRIVILEGED |
| 713 |
|
| 714 |
if (!access_inited) |
| 715 |
abort (); |
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
#ifndef HAVE_SETREUID |
| 721 |
if (setuid (user_uid) < 0) |
| 722 |
pfatal_with_name ("child_access: setuid"); |
| 723 |
#else |
| 724 |
if (setreuid (user_uid, user_uid) < 0) |
| 725 |
pfatal_with_name ("child_access: setreuid"); |
| 726 |
#endif |
| 727 |
|
| 728 |
#ifndef HAVE_SETREGID |
| 729 |
if (setgid (user_gid) < 0) |
| 730 |
pfatal_with_name ("child_access: setgid"); |
| 731 |
#else |
| 732 |
if (setregid (user_gid, user_gid) < 0) |
| 733 |
pfatal_with_name ("child_access: setregid"); |
| 734 |
#endif |
| 735 |
|
| 736 |
log_access (_("Child access")); |
| 737 |
|
| 738 |
#endif |
| 739 |
} |
| 740 |
|
| 741 |
#ifdef NEED_GET_PATH_MAX |
| 742 |
unsigned int |
| 743 |
get_path_max (void) |
| 744 |
{ |
| 745 |
static unsigned int value; |
| 746 |
|
| 747 |
if (value == 0) |
| 748 |
{ |
| 749 |
long int x = pathconf ("/", _PC_PATH_MAX); |
| 750 |
if (x > 0) |
| 751 |
value = x; |
| 752 |
else |
| 753 |
return MAXPATHLEN; |
| 754 |
} |
| 755 |
|
| 756 |
return value; |
| 757 |
} |
| 758 |
#endif |
| 759 |
|
| 760 |
|
| 761 |
#ifndef UCHAR_MAX |
| 762 |
# define UCHAR_MAX 255 |
| 763 |
#endif |
| 764 |
unsigned short stopchar_map[UCHAR_MAX + 1] = {0}; |
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
extern void |
| 770 |
initialize_stopchar_map (void) |
| 771 |
{ |
| 772 |
int i; |
| 773 |
stopchar_map[(int)'\0'] = MAP_NUL; |
| 774 |
stopchar_map[(int)'#'] = MAP_COMMENT; |
| 775 |
stopchar_map[(int)';'] = MAP_SEMI; |
| 776 |
stopchar_map[(int)'='] = MAP_EQUALS; |
| 777 |
stopchar_map[(int)':'] = MAP_COLON; |
| 778 |
stopchar_map[(int)'|'] = MAP_PIPE; |
| 779 |
stopchar_map[(int)'.'] = MAP_DOT | MAP_USERFUNC; |
| 780 |
stopchar_map[(int)','] = MAP_COMMA; |
| 781 |
stopchar_map[(int)'('] = MAP_VARSEP; |
| 782 |
stopchar_map[(int)'{'] = MAP_VARSEP; |
| 783 |
stopchar_map[(int)'}'] = MAP_VARSEP; |
| 784 |
stopchar_map[(int)')'] = MAP_VARSEP; |
| 785 |
stopchar_map[(int)'$'] = MAP_VARIABLE; |
| 786 |
|
| 787 |
stopchar_map[(int)'-'] = MAP_USERFUNC; |
| 788 |
stopchar_map[(int)'_'] = MAP_USERFUNC; |
| 789 |
|
| 790 |
stopchar_map[(int)' '] = MAP_BLANK; |
| 791 |
stopchar_map[(int)'\t'] = MAP_BLANK; |
| 792 |
|
| 793 |
stopchar_map[(int)'/'] = MAP_DIRSEP; |
| 794 |
|
| 795 |
#if defined(HAVE_DOS_PATHS) |
| 796 |
stopchar_map[(int)'\\'] = MAP_DIRSEP; |
| 797 |
#endif |
| 798 |
|
| 799 |
for (i = 1; i <= UCHAR_MAX; ++i) |
| 800 |
{ |
| 801 |
if (isspace (i) && NONE_SET (stopchar_map[i], MAP_BLANK)) |
| 802 |
|
| 803 |
stopchar_map[i] |= MAP_NEWLINE; |
| 804 |
else if (isalnum (i)) |
| 805 |
stopchar_map[i] |= MAP_USERFUNC; |
| 806 |
} |
| 807 |
} |