packvfs

diff src/pvfs.c @ 2:dc23ab0545a6

- fleshed out some more fucntions with the code for the case where file/dir are real - added install/uninstall targets to the makefile - added pvfsh (packvfs shell) test program
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 04 Nov 2013 03:50:55 +0200
parents a0b3b6682d92
children
line diff
     1.1 --- a/src/pvfs.c	Mon Nov 04 01:01:22 2013 +0200
     1.2 +++ b/src/pvfs.c	Mon Nov 04 03:50:55 2013 +0200
     1.3 @@ -153,12 +153,43 @@
     1.4  	return -1;
     1.5  }
     1.6  
     1.7 -int pvfs_fseek(PVFS_FILE *fp, long offset, int whence);
     1.8 -long pvfs_ftell(PVFS_FILE *fp);
     1.9 -void pvfs_rewind(PVFS_FILE *fp);
    1.10 +int pvfs_fseek(PVFS_FILE *fp, long offset, int whence)
    1.11 +{
    1.12 +	if(fp->real) {
    1.13 +		return fseek(fp->fp, offset, whence);
    1.14 +	}
    1.15  
    1.16 -size_t pvfs_fread(void *buf, size_t size, size_t nitems, PVFS_FILE *fp);
    1.17 -size_t pvfs_fwrite(void *buf, size_t size, size_t nitems, PVFS_FILE *fp);
    1.18 +	return -1;	/* TODO */
    1.19 +}
    1.20 +
    1.21 +long pvfs_ftell(PVFS_FILE *fp)
    1.22 +{
    1.23 +	if(fp->real) {
    1.24 +		return ftell(fp->fp);
    1.25 +	}
    1.26 +	return -1;	/* TODO */
    1.27 +}
    1.28 +
    1.29 +void pvfs_rewind(PVFS_FILE *fp)
    1.30 +{
    1.31 +	pvfs_fseek(fp, 0, SEEK_SET);
    1.32 +}
    1.33 +
    1.34 +size_t pvfs_fread(void *buf, size_t size, size_t nitems, PVFS_FILE *fp)
    1.35 +{
    1.36 +	if(fp->real) {
    1.37 +		return fread(buf, size, nitems, fp->fp);
    1.38 +	}
    1.39 +	return 0;	/* TODO */
    1.40 +}
    1.41 +
    1.42 +size_t pvfs_fwrite(void *buf, size_t size, size_t nitems, PVFS_FILE *fp)
    1.43 +{
    1.44 +	if(fp->real) {
    1.45 +		return fwrite(buf, size, nitems, fp->fp);
    1.46 +	}
    1.47 +	return 0;	/* TODO */
    1.48 +}
    1.49  
    1.50  int pvfs_fgetc(PVFS_FILE *fp)
    1.51  {
    1.52 @@ -221,6 +252,7 @@
    1.53  
    1.54  	va_start(ap, fmt);
    1.55  	res = pvfs_vfprintf(fp, fmt, ap);
    1.56 +
    1.57  	va_end(ap);
    1.58  	return res;
    1.59  }
    1.60 @@ -230,9 +262,30 @@
    1.61  	return 0; /* TODO */
    1.62  }
    1.63  
    1.64 -void pvfs_clearerr(PVFS_FILE *fp);
    1.65 -int pvfs_feof(PVFS_FILE *fp);
    1.66 -int pvfs_ferror(PVFS_FILE *fp);
    1.67 +void pvfs_clearerr(PVFS_FILE *fp)
    1.68 +{
    1.69 +	if(fp->real) {
    1.70 +		clearerr(fp->fp);
    1.71 +		return;
    1.72 +	}
    1.73 +	/* TODO */
    1.74 +}
    1.75 +
    1.76 +int pvfs_feof(PVFS_FILE *fp)
    1.77 +{
    1.78 +	if(fp->real) {
    1.79 +		return feof(fp->fp);
    1.80 +	}
    1.81 +	return 0;	/* TODO */
    1.82 +}
    1.83 +
    1.84 +int pvfs_ferror(PVFS_FILE *fp)
    1.85 +{
    1.86 +	if(fp->real) {
    1.87 +		return ferror(fp->fp);
    1.88 +	}
    1.89 +	return -1;	/* TODO */
    1.90 +}
    1.91  
    1.92  /* POSIX stuff */
    1.93  PVFS_DIR *pvfs_opendir(const char *dirname)
    1.94 @@ -274,8 +327,35 @@
    1.95  	return -1;
    1.96  }
    1.97  
    1.98 -struct pvfs_dirent *pvfs_readdir(PVFS_DIR *dir);
    1.99 -void pvfs_rewinddir(PVFS_DIR *dir);
   1.100 +struct pvfs_dirent *pvfs_readdir(PVFS_DIR *dir)
   1.101 +{
   1.102 +	static struct pvfs_dirent dent;
   1.103  
   1.104 -int pvfs_stat(const char *path, struct pvfs_stat *buf);
   1.105 +	if(dir->real) {
   1.106 +		struct dirent *real_dent = readdir(dir->dir);
   1.107 +		if(!real_dent) {
   1.108 +			pvfs_errno = errno;
   1.109 +			return 0;
   1.110 +		}
   1.111  
   1.112 +		strncpy(dent.d_name, real_dent->d_name, sizeof dent.d_name - 1);
   1.113 +		dent.d_name[sizeof dent.d_name - 1] = 0;
   1.114 +
   1.115 +		return &dent;
   1.116 +	}
   1.117 +	return 0;	/* TODO */
   1.118 +}
   1.119 +
   1.120 +void pvfs_rewinddir(PVFS_DIR *dir)
   1.121 +{
   1.122 +	if(dir->real) {
   1.123 +		rewinddir(dir->dir);
   1.124 +		return;
   1.125 +	}
   1.126 +	/* TODO */
   1.127 +}
   1.128 +
   1.129 +int pvfs_stat(const char *path, struct pvfs_stat *buf)
   1.130 +{
   1.131 +	return -1;	/* TODO */
   1.132 +}