Moved some utility functions into their own file.
This commit is contained in:
parent
78eb2cbf6a
commit
3cbe112926
2 changed files with 49 additions and 0 deletions
26
src/lladd/io.c
Normal file
26
src/lladd/io.c
Normal file
|
@ -0,0 +1,26 @@
|
|||
#include "io.h"
|
||||
#include <stdlib.h>
|
||||
long myFseek(FILE * f, long offset, int whence) {
|
||||
long ret;
|
||||
flockfile(f);
|
||||
ret = myFseekNoLock(f, offset, whence);
|
||||
funlockfile(f);
|
||||
return ret;
|
||||
}
|
||||
|
||||
long myFseekNoLock(FILE * f, long offset, int whence) {
|
||||
long ret;
|
||||
if(0 != fseek(f, offset, whence)) { perror ("fseek"); fflush(NULL); abort(); }
|
||||
if(-1 == (ret = ftell(f))) { perror("ftell"); fflush(NULL); abort(); }
|
||||
return ret;
|
||||
}
|
||||
|
||||
void myFwrite(const void * dat, long size, FILE * f) {
|
||||
int nmemb = fwrite(dat, size, 1, f);
|
||||
/* test */
|
||||
if(nmemb != 1) {
|
||||
perror("myFwrite");
|
||||
abort();
|
||||
/* return FILE_WRITE_OPEN_ERROR; */
|
||||
}
|
||||
}
|
23
src/lladd/io.h
Normal file
23
src/lladd/io.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
/**
|
||||
@file
|
||||
|
||||
A few io wrapper functions to simplify file I/O code in LLADD.
|
||||
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <lladd/common.h>
|
||||
|
||||
BEGIN_C_DECLS
|
||||
|
||||
|
||||
#ifndef __LLADD_IO_H
|
||||
#define __LLADD_IO_H
|
||||
|
||||
long myFseek(FILE * f, long offset, int whence);
|
||||
long myFseekNoLock(FILE * f, long offset, int whence);
|
||||
void myFwrite(const void * dat, long size, FILE * f);
|
||||
|
||||
END_C_DECLS
|
||||
|
||||
#endif /* __LLADD_IO_H */
|
Loading…
Reference in a new issue