2003-06-11 23:36:48 +00:00
|
|
|
// The contents of this file are subject to the BOINC Public License
|
2002-09-26 18:11:06 +00:00
|
|
|
// Version 1.0 (the "License"); you may not use this file except in
|
|
|
|
// compliance with the License. You may obtain a copy of the License at
|
2003-06-11 23:36:48 +00:00
|
|
|
// http://boinc.berkeley.edu/license_1.0.txt
|
2003-08-15 00:50:58 +00:00
|
|
|
//
|
2002-09-26 18:11:06 +00:00
|
|
|
// Software distributed under the License is distributed on an "AS IS"
|
|
|
|
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
|
|
|
// License for the specific language governing rights and limitations
|
2003-08-15 00:50:58 +00:00
|
|
|
// under the License.
|
|
|
|
//
|
|
|
|
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
|
|
|
|
//
|
2002-09-26 18:11:06 +00:00
|
|
|
// The Initial Developer of the Original Code is the SETI@home project.
|
|
|
|
// Portions created by the SETI@home project are Copyright (C) 2002
|
2003-08-15 00:50:58 +00:00
|
|
|
// University of California at Berkeley. All Rights Reserved.
|
|
|
|
//
|
2002-09-26 18:11:06 +00:00
|
|
|
// Contributor(s):
|
|
|
|
//
|
|
|
|
|
2002-08-05 00:29:34 +00:00
|
|
|
#include <stdio.h>
|
2002-09-04 19:55:19 +00:00
|
|
|
#include <stdlib.h>
|
2002-08-05 00:29:34 +00:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
2002-09-04 19:55:19 +00:00
|
|
|
#if HAVE_MALLOC_H
|
2002-08-05 00:29:34 +00:00
|
|
|
#include <malloc.h>
|
2002-09-04 19:55:19 +00:00
|
|
|
#endif
|
2002-08-05 00:29:34 +00:00
|
|
|
|
2003-12-24 00:50:51 +00:00
|
|
|
#include "filesys.h"
|
2002-08-05 00:29:34 +00:00
|
|
|
#include "boinc_api.h"
|
|
|
|
|
2003-10-29 11:05:39 +00:00
|
|
|
int MFILE::open(const char* path, const char* mode) {
|
2002-08-05 00:29:34 +00:00
|
|
|
buf = 0;
|
|
|
|
len = 0;
|
2003-12-24 00:50:51 +00:00
|
|
|
f = boinc_fopen(path, mode);
|
2002-08-05 00:29:34 +00:00
|
|
|
if (!f) return -1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-10-29 11:05:39 +00:00
|
|
|
int MFILE::printf(const char* format, ...) {
|
2002-08-05 00:29:34 +00:00
|
|
|
va_list ap;
|
2003-10-23 22:40:27 +00:00
|
|
|
char buf2[20000];
|
2002-08-05 00:29:34 +00:00
|
|
|
int n, k;
|
|
|
|
|
|
|
|
va_start(ap, format);
|
|
|
|
k = vsprintf(buf2, format, ap);
|
|
|
|
va_end(ap);
|
|
|
|
n = strlen(buf2);
|
|
|
|
buf = (char*)realloc(buf, len+n);
|
|
|
|
strncpy(buf+len, buf2, n);
|
|
|
|
len += n;
|
|
|
|
return k;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t MFILE::write(const void *ptr, size_t size, size_t nitems) {
|
|
|
|
buf = (char *)realloc( buf, len+(size*nitems) );
|
|
|
|
memcpy( buf+len, ptr, size*nitems );
|
|
|
|
len += size*nitems;
|
|
|
|
return nitems;
|
|
|
|
}
|
|
|
|
|
|
|
|
int MFILE::_putchar(char c) {
|
|
|
|
buf = (char*)realloc(buf, len+1);
|
|
|
|
buf[len] = c;
|
|
|
|
len++;
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2003-10-29 11:05:39 +00:00
|
|
|
int MFILE::puts(const char* p) {
|
2002-08-05 00:29:34 +00:00
|
|
|
int n = strlen(p);
|
|
|
|
buf = (char*)realloc(buf, len+n);
|
|
|
|
strncpy(buf+len, p, n);
|
|
|
|
len += n;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int MFILE::close() {
|
|
|
|
fwrite(buf, 1, len, f);
|
|
|
|
free(buf);
|
|
|
|
buf = 0;
|
|
|
|
return fclose(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
int MFILE::flush() {
|
|
|
|
fwrite(buf, 1, len, f);
|
|
|
|
len = 0;
|
|
|
|
return fflush(f);
|
|
|
|
}
|
2003-08-15 00:50:58 +00:00
|
|
|
|
|
|
|
long MFILE::tell() const
|
|
|
|
{
|
|
|
|
return f ? ftell(f) : -1;
|
|
|
|
}
|