fio.c (da52b4caaf187775f6b56a72c6b16e94ad728f7b) | fio.c (6d8484b0d0191b66f9bfd0dfa89c06a29647f02a) |
---|---|
1/* 2 * Copyright (c) 1980, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 42 unchanged lines hidden (view full) --- 51 */ 52 53extern int wait_status; 54 55/* 56 * Set up the input pointers while copying the mail file into /tmp. 57 */ 58void | 1/* 2 * Copyright (c) 1980, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 42 unchanged lines hidden (view full) --- 51 */ 52 53extern int wait_status; 54 55/* 56 * Set up the input pointers while copying the mail file into /tmp. 57 */ 58void |
59setptr(ibuf, offset) 60 FILE *ibuf; 61 off_t offset; | 59setptr(FILE *ibuf, off_t offset) |
62{ 63 int c, count; 64 char *cp, *cp2; 65 struct message this; 66 FILE *mestmp; 67 int maybe, inhead; 68 char linebuf[LINESIZE], pathbuf[PATHSIZE]; 69 int omsgCount; --- 88 unchanged lines hidden (view full) --- 158} 159 160/* 161 * Drop the passed line onto the passed output buffer. 162 * If a write error occurs, return -1, else the count of 163 * characters written, including the newline if requested. 164 */ 165int | 60{ 61 int c, count; 62 char *cp, *cp2; 63 struct message this; 64 FILE *mestmp; 65 int maybe, inhead; 66 char linebuf[LINESIZE], pathbuf[PATHSIZE]; 67 int omsgCount; --- 88 unchanged lines hidden (view full) --- 156} 157 158/* 159 * Drop the passed line onto the passed output buffer. 160 * If a write error occurs, return -1, else the count of 161 * characters written, including the newline if requested. 162 */ 163int |
166putline(obuf, linebuf, outlf) 167 FILE *obuf; 168 char *linebuf; 169 int outlf; | 164putline(FILE *obuf, char *linebuf, int outlf) |
170{ 171 int c; 172 173 c = strlen(linebuf); 174 (void)fwrite(linebuf, sizeof(*linebuf), c, obuf); 175 if (outlf) { 176 fprintf(obuf, "\n"); 177 c++; --- 4 unchanged lines hidden (view full) --- 182} 183 184/* 185 * Read up a line from the specified input into the line 186 * buffer. Return the number of characters read. Do not 187 * include the newline (or carriage return) at the end. 188 */ 189int | 165{ 166 int c; 167 168 c = strlen(linebuf); 169 (void)fwrite(linebuf, sizeof(*linebuf), c, obuf); 170 if (outlf) { 171 fprintf(obuf, "\n"); 172 c++; --- 4 unchanged lines hidden (view full) --- 177} 178 179/* 180 * Read up a line from the specified input into the line 181 * buffer. Return the number of characters read. Do not 182 * include the newline (or carriage return) at the end. 183 */ 184int |
190readline(ibuf, linebuf, linesize) 191 FILE *ibuf; 192 char *linebuf; 193 int linesize; | 185readline(FILE *ibuf, char *linebuf, int linesize) |
194{ 195 int n; 196 197 clearerr(ibuf); 198 if (fgets(linebuf, linesize, ibuf) == NULL) 199 return (-1); 200 n = strlen(linebuf); 201 if (n > 0 && linebuf[n - 1] == '\n') 202 linebuf[--n] = '\0'; 203 if (n > 0 && linebuf[n - 1] == '\r') 204 linebuf[--n] = '\0'; 205 return (n); 206} 207 208/* 209 * Return a file buffer all ready to read up the 210 * passed message pointer. 211 */ 212FILE * | 186{ 187 int n; 188 189 clearerr(ibuf); 190 if (fgets(linebuf, linesize, ibuf) == NULL) 191 return (-1); 192 n = strlen(linebuf); 193 if (n > 0 && linebuf[n - 1] == '\n') 194 linebuf[--n] = '\0'; 195 if (n > 0 && linebuf[n - 1] == '\r') 196 linebuf[--n] = '\0'; 197 return (n); 198} 199 200/* 201 * Return a file buffer all ready to read up the 202 * passed message pointer. 203 */ 204FILE * |
213setinput(mp) 214 struct message *mp; | 205setinput(struct message *mp) |
215{ 216 217 (void)fflush(otf); 218 if (fseeko(itf, 219 positionof(mp->m_block, mp->m_offset), SEEK_SET) < 0) 220 err(1, "fseeko"); 221 return (itf); 222} 223 224/* 225 * Take the data out of the passed ghost file and toss it into 226 * a dynamically allocated message structure. 227 */ 228void | 206{ 207 208 (void)fflush(otf); 209 if (fseeko(itf, 210 positionof(mp->m_block, mp->m_offset), SEEK_SET) < 0) 211 err(1, "fseeko"); 212 return (itf); 213} 214 215/* 216 * Take the data out of the passed ghost file and toss it into 217 * a dynamically allocated message structure. 218 */ 219void |
229makemessage(f, omsgCount) 230 FILE *f; 231 int omsgCount; | 220makemessage(FILE *f, int omsgCount) |
232{ 233 size_t size; 234 struct message *nmessage; 235 236 size = (msgCount + 1) * sizeof(struct message); 237 nmessage = (struct message *)realloc(message, size); 238 if (nmessage == NULL) 239 errx(1, "Insufficient memory for %d messages\n", --- 13 unchanged lines hidden (view full) --- 253 (void)Fclose(f); 254} 255 256/* 257 * Append the passed message descriptor onto the temp file. 258 * If the write fails, return 1, else 0 259 */ 260int | 221{ 222 size_t size; 223 struct message *nmessage; 224 225 size = (msgCount + 1) * sizeof(struct message); 226 nmessage = (struct message *)realloc(message, size); 227 if (nmessage == NULL) 228 errx(1, "Insufficient memory for %d messages\n", --- 13 unchanged lines hidden (view full) --- 242 (void)Fclose(f); 243} 244 245/* 246 * Append the passed message descriptor onto the temp file. 247 * If the write fails, return 1, else 0 248 */ 249int |
261append(mp, f) 262 struct message *mp; 263 FILE *f; | 250append(struct message *mp, FILE *f) |
264{ 265 return (fwrite((char *)mp, sizeof(*mp), 1, f) != 1); 266} 267 268/* 269 * Delete a file, but only if the file is a plain file. 270 */ 271int | 251{ 252 return (fwrite((char *)mp, sizeof(*mp), 1, f) != 1); 253} 254 255/* 256 * Delete a file, but only if the file is a plain file. 257 */ 258int |
272rm(name) 273 char *name; | 259rm(char *name) |
274{ 275 struct stat sb; 276 277 if (stat(name, &sb) < 0) 278 return (-1); 279 if (!S_ISREG(sb.st_mode)) { 280 errno = EISDIR; 281 return (-1); 282 } 283 return (unlink(name)); 284} 285 286static int sigdepth; /* depth of holdsigs() */ 287static sigset_t nset, oset; 288/* 289 * Hold signals SIGHUP, SIGINT, and SIGQUIT. 290 */ 291void | 260{ 261 struct stat sb; 262 263 if (stat(name, &sb) < 0) 264 return (-1); 265 if (!S_ISREG(sb.st_mode)) { 266 errno = EISDIR; 267 return (-1); 268 } 269 return (unlink(name)); 270} 271 272static int sigdepth; /* depth of holdsigs() */ 273static sigset_t nset, oset; 274/* 275 * Hold signals SIGHUP, SIGINT, and SIGQUIT. 276 */ 277void |
292holdsigs() | 278holdsigs(void) |
293{ 294 295 if (sigdepth++ == 0) { 296 (void)sigemptyset(&nset); 297 (void)sigaddset(&nset, SIGHUP); 298 (void)sigaddset(&nset, SIGINT); 299 (void)sigaddset(&nset, SIGQUIT); 300 (void)sigprocmask(SIG_BLOCK, &nset, &oset); 301 } 302} 303 304/* 305 * Release signals SIGHUP, SIGINT, and SIGQUIT. 306 */ 307void | 279{ 280 281 if (sigdepth++ == 0) { 282 (void)sigemptyset(&nset); 283 (void)sigaddset(&nset, SIGHUP); 284 (void)sigaddset(&nset, SIGINT); 285 (void)sigaddset(&nset, SIGQUIT); 286 (void)sigprocmask(SIG_BLOCK, &nset, &oset); 287 } 288} 289 290/* 291 * Release signals SIGHUP, SIGINT, and SIGQUIT. 292 */ 293void |
308relsesigs() | 294relsesigs(void) |
309{ 310 311 if (--sigdepth == 0) 312 (void)sigprocmask(SIG_SETMASK, &oset, NULL); 313} 314 315/* 316 * Determine the size of the file possessed by 317 * the passed buffer. 318 */ 319off_t | 295{ 296 297 if (--sigdepth == 0) 298 (void)sigprocmask(SIG_SETMASK, &oset, NULL); 299} 300 301/* 302 * Determine the size of the file possessed by 303 * the passed buffer. 304 */ 305off_t |
320fsize(iob) 321 FILE *iob; | 306fsize(FILE *iob) |
322{ 323 struct stat sbuf; 324 325 if (fstat(fileno(iob), &sbuf) < 0) 326 return (0); 327 return (sbuf.st_size); 328} 329 --- 4 unchanged lines hidden (view full) --- 334 * %user for user's system mail box 335 * # for previous file 336 * & invoker's mbox file 337 * +file file in folder directory 338 * any shell meta character 339 * Return the file name as a dynamic string. 340 */ 341char * | 307{ 308 struct stat sbuf; 309 310 if (fstat(fileno(iob), &sbuf) < 0) 311 return (0); 312 return (sbuf.st_size); 313} 314 --- 4 unchanged lines hidden (view full) --- 319 * %user for user's system mail box 320 * # for previous file 321 * & invoker's mbox file 322 * +file file in folder directory 323 * any shell meta character 324 * Return the file name as a dynamic string. 325 */ 326char * |
342expand(name) 343 char *name; | 327expand(char *name) |
344{ 345 char xname[PATHSIZE]; 346 char cmdbuf[PATHSIZE]; /* also used for file names */ 347 int pid, l; 348 char *cp, *sh; 349 int pivec[2]; 350 struct stat sbuf; 351 --- 75 unchanged lines hidden (view full) --- 427 } 428 return (savestr(xname)); 429} 430 431/* 432 * Determine the current folder directory name. 433 */ 434int | 328{ 329 char xname[PATHSIZE]; 330 char cmdbuf[PATHSIZE]; /* also used for file names */ 331 int pid, l; 332 char *cp, *sh; 333 int pivec[2]; 334 struct stat sbuf; 335 --- 75 unchanged lines hidden (view full) --- 411 } 412 return (savestr(xname)); 413} 414 415/* 416 * Determine the current folder directory name. 417 */ 418int |
435getfold(name, namelen) 436 char *name; 437 int namelen; | 419getfold(char *name, int namelen) |
438{ 439 char *folder; 440 int copylen; 441 442 if ((folder = value("folder")) == NULL) 443 return (-1); 444 if (*folder == '/') 445 copylen = strlcpy(name, folder, namelen); 446 else 447 copylen = snprintf(name, namelen, "%s/%s", 448 homedir ? homedir : ".", folder); 449 return (copylen < 0 || copylen >= namelen ? (-1) : (0)); 450} 451 452/* 453 * Return the name of the dead.letter file. 454 */ 455char * | 420{ 421 char *folder; 422 int copylen; 423 424 if ((folder = value("folder")) == NULL) 425 return (-1); 426 if (*folder == '/') 427 copylen = strlcpy(name, folder, namelen); 428 else 429 copylen = snprintf(name, namelen, "%s/%s", 430 homedir ? homedir : ".", folder); 431 return (copylen < 0 || copylen >= namelen ? (-1) : (0)); 432} 433 434/* 435 * Return the name of the dead.letter file. 436 */ 437char * |
456getdeadletter() | 438getdeadletter(void) |
457{ 458 char *cp; 459 460 if ((cp = value("DEAD")) == NULL || (cp = expand(cp)) == NULL) 461 cp = expand("~/dead.letter"); 462 else if (*cp != '/') { 463 char buf[PATHSIZE]; 464 465 (void)snprintf(buf, sizeof(buf), "~/%s", cp); 466 cp = expand(buf); 467 } 468 return (cp); 469} | 439{ 440 char *cp; 441 442 if ((cp = value("DEAD")) == NULL || (cp = expand(cp)) == NULL) 443 cp = expand("~/dead.letter"); 444 else if (*cp != '/') { 445 char buf[PATHSIZE]; 446 447 (void)snprintf(buf, sizeof(buf), "~/%s", cp); 448 cp = expand(buf); 449 } 450 return (cp); 451} |