1
0
mirror of https://github.com/samba-team/samba.git synced 2025-03-08 04:58:40 +03:00

added fdprintf()

this is like fprintf() but operates on a file descriptor

combined with file_load_lines() this makes it really easy to get rid
of the use of fopen() in Samba.
This commit is contained in:
Andrew Tridgell -
parent 9f49d17d4c
commit bd5cd502bf
3 changed files with 44 additions and 2 deletions

View File

@ -1303,6 +1303,16 @@ int slprintf(char *str, int n, char *format, ...)
int slprintf();
#endif
#ifdef HAVE_STDARG_H
int fdprintf(int fd, char *format, ...)
#ifdef __GNUC__
__attribute__ ((format (printf, 2, 3)))
#endif
;
#else
int fdprintf();
#endif
#ifdef WITH_DFS
void dfs_unlogin(void);
extern int dcelogin_atmost_once;

View File

@ -64,3 +64,33 @@ va_dcl
va_end(ap);
return ret;
}
/* this is rather line fprintf, except that it works on a file descriptor
and is limited to one pstring of output */
#ifdef HAVE_STDARG_H
int fdprintf(int fd, char *format, ...)
{
#else
int fdprintf(va_alist)
va_dcl
{
int fd;
char *format;
#endif
va_list ap;
int ret;
pstring str;
#ifdef HAVE_STDARG_H
va_start(ap, format);
#else
va_start(ap);
fd = va_arg(ap,int);
format = va_arg(ap,char *);
#endif
str[0] = 0;
ret = vslprintf(str,sizeof(str),format,ap);
va_end(ap);
return write(fd, str, strlen(str));
}

View File

@ -362,12 +362,13 @@ char **file_lines_load(char *fname, int *numlines)
if (s[0] == '\n') i++;
}
ret = (char **)malloc(sizeof(ret[0])*(i+1));
ret = (char **)malloc(sizeof(ret[0])*(i+2));
if (!ret) {
free(p);
return NULL;
}
*numlines = i;
memset(ret, 0, sizeof(ret[0])*(i+2));
if (numlines) *numlines = i;
ret[0] = p;
for (s = p, i=0; s < p+size; s++) {
@ -391,3 +392,4 @@ void file_lines_free(char **lines)
free(lines[0]);
free(lines);
}