mirror of https://github.com/BOINC/boinc.git
usefull functions to read file content into memory
git-svn-id: svn+ssh://cvs.lpds.sztaki.hu/var/lib/svn/szdg/dcapi/trunk@979 a7169a2c-3604-0410-bc95-c702d8d87f7a
This commit is contained in:
parent
6b6c4cc64f
commit
4dd9bf0636
|
@ -116,6 +116,53 @@ _DC_rm(char *name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
_DC_create_file(char *fn, char *what)
|
||||||
|
{
|
||||||
|
FILE *f= fopen(fn, "w");
|
||||||
|
if (f)
|
||||||
|
{
|
||||||
|
if (what)
|
||||||
|
fprintf(f, "%s", what);
|
||||||
|
fclose(f);
|
||||||
|
return(DC_OK);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return(DC_ERR_SYSTEM);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
char *
|
||||||
|
_DC_get_file(char *fn)
|
||||||
|
{
|
||||||
|
FILE *f;
|
||||||
|
char *buf= NULL;
|
||||||
|
|
||||||
|
if ((f= fopen(fn, "r")) != NULL)
|
||||||
|
{
|
||||||
|
int bs= 100, i;
|
||||||
|
char c;
|
||||||
|
|
||||||
|
buf= malloc(bs);
|
||||||
|
i= 0;
|
||||||
|
buf[i]= '\0';
|
||||||
|
while ((c= fgetc(f)) != EOF)
|
||||||
|
{
|
||||||
|
if (i > bs-2)
|
||||||
|
{
|
||||||
|
bs+= 100;
|
||||||
|
buf= realloc(buf, bs);
|
||||||
|
}
|
||||||
|
buf[i]= c;
|
||||||
|
i++;
|
||||||
|
buf[i]= '\0';
|
||||||
|
}
|
||||||
|
fclose(f);
|
||||||
|
}
|
||||||
|
return(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int _DC_message_id= 0;
|
static int _DC_message_id= 0;
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
|
@ -23,6 +23,8 @@ extern void _DC_init_utils(void);
|
||||||
/* Usefull funcs */
|
/* Usefull funcs */
|
||||||
extern int _DC_mkdir_with_parents(char *dn, mode_t mode);
|
extern int _DC_mkdir_with_parents(char *dn, mode_t mode);
|
||||||
extern int _DC_rm(char *name);
|
extern int _DC_rm(char *name);
|
||||||
|
extern int _DC_create_file(char *fn, char *what);
|
||||||
|
extern char *_DC_get_file(char *fn);
|
||||||
|
|
||||||
/* Message passing utilities */
|
/* Message passing utilities */
|
||||||
extern int _DC_create_message(char *box,
|
extern int _DC_create_message(char *box,
|
||||||
|
|
Loading…
Reference in New Issue