packvfs

changeset 1:a0b3b6682d92

*slowly* filling in some unimplemented functions
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 04 Nov 2013 01:01:22 +0200
parents df5e9ee65a50
children dc23ab0545a6
files src/pvfs.c src/pvfs.h
diffstat 2 files changed, 76 insertions(+), 14 deletions(-) [+]
line diff
     1.1 --- a/src/pvfs.c	Fri Aug 02 06:03:38 2013 +0300
     1.2 +++ b/src/pvfs.c	Mon Nov 04 01:01:22 2013 +0200
     1.3 @@ -1,6 +1,7 @@
     1.4  #include <string.h>
     1.5 +#include <stdarg.h>
     1.6 +#include <assert.h>
     1.7  #include <alloca.h>
     1.8 -#include <assert.h>
     1.9  #include "pvfs.h"
    1.10  #include "vnode.h"
    1.11  
    1.12 @@ -23,17 +24,18 @@
    1.13  
    1.14  	/* then locate the target vnode (if it exists) */
    1.15  	if(!(destnode = vnode_lookup(target))) {
    1.16 +		PVFS_DIR *dir;
    1.17 +		PVFS_FILE *fp;
    1.18 +
    1.19  		/* it's some error other than that target doesn't exist, fail... */
    1.20  		if(pvfs_errno != ENOENT) {
    1.21  			return -1;
    1.22  		}
    1.23 +
    1.24  		/* if it doesn't exist, it might be the case we're trying
    1.25  		 * to mount a package file or a real directory here. let's
    1.26  		 * try them in turn...
    1.27  		 */
    1.28 -		PVFS_DIR *dir;
    1.29 -		PVFS_FILE *fp;
    1.30 -
    1.31  		if((dir = pvfs_opendir(target))) {
    1.32  			/* it's obviously a real dir as vnode_lookup failed before... */
    1.33  			assert(dir->real);
    1.34 @@ -156,18 +158,77 @@
    1.35  void pvfs_rewind(PVFS_FILE *fp);
    1.36  
    1.37  size_t pvfs_fread(void *buf, size_t size, size_t nitems, PVFS_FILE *fp);
    1.38 -size_t pvfs_write(void *buf, size_t size, size_t nitems, PVFS_FILE *fp);
    1.39 +size_t pvfs_fwrite(void *buf, size_t size, size_t nitems, PVFS_FILE *fp);
    1.40  
    1.41 -int pvfs_fgetc(PVFS_FILE *fp);
    1.42 -int pvfs_fputc(int c, PVFS_FILE *fp);
    1.43 +int pvfs_fgetc(PVFS_FILE *fp)
    1.44 +{
    1.45 +	char c;
    1.46 +	if(pvfs_fread(&c, 1, 1, fp) != 1) {
    1.47 +		return -1;
    1.48 +	}
    1.49 +	return c;
    1.50 +}
    1.51  
    1.52 -char *pvfs_fgets(char *buf, int size, PVFS_FILE *fp);
    1.53 -int pvfs_fputs(char *buf, PVFS_FILE *fp);
    1.54 +int pvfs_fputc(int c, PVFS_FILE *fp)
    1.55 +{
    1.56 +	return pvfs_fwrite(&c, 1, 1, fp) == 1 ? 0 : -1;
    1.57 +}
    1.58  
    1.59 -int pvfs_fscanf(PVFS_FILE *fp, const char *fmt, ...);
    1.60 -int pvfs_vfscanf(PVFS_FILE *fp, const char *fmt, va_list ap);
    1.61 -int pvfs_fprintf(PVFS_FILE *fp, const char *fmt, ...);
    1.62 -int pvfs_vfprintf(PVFS_FILE *fp, const char *fmt, va_list ap);
    1.63 +char *pvfs_fgets(char *buf, int size, PVFS_FILE *fp)
    1.64 +{
    1.65 +	int i;
    1.66 +	char *res = buf;
    1.67 +
    1.68 +	for(i=0; i<size - 1; i++) {
    1.69 +		int c = pvfs_fgetc(fp);
    1.70 +		if(!c) break;
    1.71 +
    1.72 +		*buf++ = c;
    1.73 +		if(c == '\n') break;
    1.74 +	}
    1.75 +
    1.76 +	*buf = 0;
    1.77 +	return res;
    1.78 +}
    1.79 +
    1.80 +int pvfs_fputs(char *buf, PVFS_FILE *fp)
    1.81 +{
    1.82 +	int len = strlen(buf);
    1.83 +
    1.84 +	return pvfs_fwrite(buf, 1, len, fp) == 1 ? 0 : -1;
    1.85 +}
    1.86 +
    1.87 +int pvfs_fscanf(PVFS_FILE *fp, const char *fmt, ...)
    1.88 +{
    1.89 +	va_list ap;
    1.90 +	int res;
    1.91 +
    1.92 +	va_start(ap, fmt);
    1.93 +	res = pvfs_vfscanf(fp, fmt, ap);
    1.94 +	va_end(ap);
    1.95 +	return res;
    1.96 +}
    1.97 +
    1.98 +int pvfs_vfscanf(PVFS_FILE *fp, const char *fmt, va_list ap)
    1.99 +{
   1.100 +	return 0;	/* TODO */
   1.101 +}
   1.102 +
   1.103 +int pvfs_fprintf(PVFS_FILE *fp, const char *fmt, ...)
   1.104 +{
   1.105 +	va_list ap;
   1.106 +	int res;
   1.107 +
   1.108 +	va_start(ap, fmt);
   1.109 +	res = pvfs_vfprintf(fp, fmt, ap);
   1.110 +	va_end(ap);
   1.111 +	return res;
   1.112 +}
   1.113 +
   1.114 +int pvfs_vfprintf(PVFS_FILE *fp, const char *fmt, va_list ap)
   1.115 +{
   1.116 +	return 0; /* TODO */
   1.117 +}
   1.118  
   1.119  void pvfs_clearerr(PVFS_FILE *fp);
   1.120  int pvfs_feof(PVFS_FILE *fp);
   1.121 @@ -212,6 +273,7 @@
   1.122  	/* TODO */
   1.123  	return -1;
   1.124  }
   1.125 +
   1.126  struct pvfs_dirent *pvfs_readdir(PVFS_DIR *dir);
   1.127  void pvfs_rewinddir(PVFS_DIR *dir);
   1.128  
     2.1 --- a/src/pvfs.h	Fri Aug 02 06:03:38 2013 +0300
     2.2 +++ b/src/pvfs.h	Mon Nov 04 01:01:22 2013 +0200
     2.3 @@ -38,7 +38,7 @@
     2.4  void pvfs_rewind(PVFS_FILE *fp);
     2.5  
     2.6  size_t pvfs_fread(void *buf, size_t size, size_t nitems, PVFS_FILE *fp);
     2.7 -size_t pvfs_write(void *buf, size_t size, size_t nitems, PVFS_FILE *fp);
     2.8 +size_t pvfs_fwrite(void *buf, size_t size, size_t nitems, PVFS_FILE *fp);
     2.9  
    2.10  int pvfs_fgetc(PVFS_FILE *fp);
    2.11  int pvfs_fputc(int c, PVFS_FILE *fp);