123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- #include <stdarg.h>
- #include <errno.h>
- #include <stdlib.h>
- #include <string.h>
- #include <unistd.h>
- #include "minix_fs.h"
- #include "protos.h"
- void fatalmsg(const char *s,...) {
- va_list p;
- va_start(p,s);
- vfprintf(stderr,s,p);
- va_end(p);
- putc('\n',stderr);
- exit(-1);
- }
- void die(const char *s,...) {
- va_list p;
- va_start(p,s);
- vfprintf(stderr,s,p);
- va_end(p);
- putc(':',stderr);
- putc(' ',stderr);
- perror(NULL);
- putc('\n',stderr);
- exit(errno);
- }
- FILE *goto_blk(FILE *fp,int blk) {
- fflush(fp);
- if (fseek(fp,blk*BLOCK_SIZE,SEEK_SET)) {
- die("fseek");
- }
- return fp;
- }
- void *dofwrite(FILE *fp,void *buff,int cnt) {
- if (cnt != fwrite(buff,1,cnt,fp)) {
- die("fwrite");
- }
- return buff;
- }
- void *dofread(FILE *fp,void *buff,int cnt) {
- if (cnt != fread(buff,1,cnt,fp)) {
- die("fread");
- }
- return buff;
- }
- void *domalloc(unsigned long size,int elm) {
- void *ptr = malloc(size);
- if (!ptr) {
- die("malloc");
- }
- if (elm >= 0) {
- memset(ptr,elm,size);
- }
- return ptr;
- }
- int dogetuid(void) {
- if (opt_squash) return 0;
- return getuid();
- }
- int dogetgid(void) {
- if (opt_squash) return 0;
- return getgid();
- }
|