Example #1
0
//move file from our file system to NT
int exportfile(char *fname,char *ntfname) {
	FILE *f;
	char *buf;
	minifile_t file;
	file = minifile_open(fname,"r");
	if(file == NULL) { printf("export: cannot open %s\n",fname); return -1; }
	buf = malloc(minifile_stat(fname));
	minifile_read(file,buf,minifile_stat(fname));
	minifile_close(file);
	if((f = fopen(ntfname,"wb")) == NULL) {	printf("export: cannot open %s\n",ntfname); return -1; }
	fwrite(buf,minifile_stat(fname),1,f);
	fclose(f);
	free(buf);
	return 0;
}
Example #2
0
//copy a file within our FS
int copy(char *fname,char *fname2)
{
    minifile_t src, dest;
    char buf[COPY_BUFFER_SIZE];
    int i,len;
    if(strcmp(fname,"")==0||strcmp(fname2,"")==0) {
        printf("Usage: cp [source_path] [dest_path]\n");
        return -1;
    }
    src = minifile_open(fname,"r");
    if(src == NULL) {
        printf("cp: couldn't open source %s!\n",fname);
        return -1;
    }
    dest = minifile_creat(fname2);
    if(dest == NULL) {
        printf("cp: couldn't create destination %s!\n",fname2);
        return -1;
    }
    len = minifile_stat(fname);
    for(i=COPY_BUFFER_SIZE; i<len; i+=COPY_BUFFER_SIZE) {
        minifile_read(src,buf,COPY_BUFFER_SIZE);
        minifile_write(dest,buf,COPY_BUFFER_SIZE);
    }
    if(i>len) {
        minifile_read(src,buf,COPY_BUFFER_SIZE-i+len);
        minifile_write(dest,buf,COPY_BUFFER_SIZE-i+len);
    }
    printf("\n");
    minifile_close(src);
    minifile_close(dest);
    return 0;
}
Example #3
0
//print a file on the screen
int typefile(char *fname)
{
    minifile_t file;
    char buf[COPY_BUFFER_SIZE+1];
    int i,len;
    buf[COPY_BUFFER_SIZE] = '\0';
    file = minifile_open(fname,"r");
    if(file == NULL) {
        printf("type: couldn't open %s!\n",fname);
        return -1;
    }
    len = minifile_stat(fname);
    for(i=COPY_BUFFER_SIZE; i<len; i+=COPY_BUFFER_SIZE) {
        minifile_read(file,buf,COPY_BUFFER_SIZE);
        printf("%s",buf);
    }
    if(i>len) {
        minifile_read(file,buf,COPY_BUFFER_SIZE-i+len);
        memset(buf+COPY_BUFFER_SIZE-i+len,'\0',i-len);
        printf("%s",buf);
    }

    printf("\nEOF\n");
    minifile_close(file);
    return 0;
}