| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include <config.h> |
| 20 |
#include <stdio.h> |
| 21 |
#include <errno.h> |
| 22 |
#include <stdlib.h> |
| 23 |
#include <string.h> |
| 24 |
#include <obstack.h> |
| 25 |
#include <error.h> |
| 26 |
#include <sys/stat.h> |
| 27 |
|
| 28 |
#include "idfile.h" |
| 29 |
#include "xalloc.h" |
| 30 |
#include "xnls.h" |
| 31 |
|
| 32 |
static int io_size (FILE *, void *, unsigned int size, int); |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
char const * |
| 43 |
locate_id_file_name (char const *arg) |
| 44 |
{ |
| 45 |
static char file_name_buffer[BUFSIZ]; |
| 46 |
char *buf = file_name_buffer; |
| 47 |
char *id_path = 0; |
| 48 |
struct stat rootb; |
| 49 |
struct stat statb; |
| 50 |
|
| 51 |
if (arg == 0) |
| 52 |
{ |
| 53 |
id_path = getenv ("IDPATH"); |
| 54 |
if (id_path) |
| 55 |
{ |
| 56 |
id_path = xstrdup (id_path); |
| 57 |
arg = strsep (&id_path, ":"); |
| 58 |
|
| 59 |
} |
| 60 |
} |
| 61 |
if (arg == 0) |
| 62 |
arg = DEFAULT_ID_FILE_NAME; |
| 63 |
|
| 64 |
|
| 65 |
if (arg[0] == '/') |
| 66 |
return arg; |
| 67 |
|
| 68 |
if (stat (arg, &statb) == 0) |
| 69 |
return arg; |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
if (stat ("/", &rootb) != 0) |
| 76 |
return NULL; |
| 77 |
do |
| 78 |
{ |
| 79 |
strcpy (buf, "../"); |
| 80 |
buf += 3; |
| 81 |
strcpy (buf, arg); |
| 82 |
if (stat (file_name_buffer, &statb) == 0) |
| 83 |
return file_name_buffer; |
| 84 |
*buf = '\0'; |
| 85 |
if (stat (file_name_buffer, &statb) != 0) |
| 86 |
return NULL; |
| 87 |
} |
| 88 |
while (statb.st_ino != rootb.st_ino || statb.st_dev != rootb.st_dev); |
| 89 |
return NULL; |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
int |
| 96 |
sizeof_idhead (void) |
| 97 |
{ |
| 98 |
return io_idhead (0, io_size, 0); |
| 99 |
} |
| 100 |
|
| 101 |
static int |
| 102 |
io_size (FILE *ignore_FILE, void *ignore_addr, unsigned int size, int io_type) |
| 103 |
{ |
| 104 |
if (io_type == IO_TYPE_STR) |
| 105 |
error (0, 0, _("can't determine the io_size of a string!")); |
| 106 |
return size; |
| 107 |
} |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
int |
| 115 |
io_idhead (FILE *fp, io_func_t iof, struct idhead *idhp) |
| 116 |
{ |
| 117 |
unsigned int size = 0; |
| 118 |
unsigned char pad = 0; |
| 119 |
if (fp) |
| 120 |
fseek (fp, 0L, 0); |
| 121 |
size += iof (fp, idhp->idh_magic, 2, IO_TYPE_FIX); |
| 122 |
size += iof (fp, &pad, 1, IO_TYPE_FIX); |
| 123 |
size += iof (fp, &idhp->idh_version, 1, IO_TYPE_FIX); |
| 124 |
size += iof (fp, &idhp->idh_flags, 2, IO_TYPE_INT); |
| 125 |
size += iof (fp, &idhp->idh_file_links, 4, IO_TYPE_INT); |
| 126 |
size += iof (fp, &idhp->idh_files, 4, IO_TYPE_INT); |
| 127 |
size += iof (fp, &idhp->idh_tokens, 4, IO_TYPE_INT); |
| 128 |
size += iof (fp, &idhp->idh_buf_size, 4, IO_TYPE_INT); |
| 129 |
size += iof (fp, &idhp->idh_vec_size, 4, IO_TYPE_INT); |
| 130 |
size += iof (fp, &idhp->idh_tokens_offset, 4, IO_TYPE_INT); |
| 131 |
size += iof (fp, &idhp->idh_flinks_offset, 4, IO_TYPE_INT); |
| 132 |
size += iof (fp, &idhp->idh_end_offset, 4, IO_TYPE_INT); |
| 133 |
size += iof (fp, &idhp->idh_max_link, 2, IO_TYPE_INT); |
| 134 |
size += iof (fp, &idhp->idh_max_path, 2, IO_TYPE_INT); |
| 135 |
return size; |
| 136 |
} |