summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2000-04-16 09:40:02 +0000
committerAndrew Tridgell <tridge@samba.org>2000-04-16 09:40:02 +0000
commit37c0312def0b0c1b3c4248bd8d797db15d88d772 (patch)
tree8dcb976c17049887e27d4119a900200ad29c56ea
parentd79a8c68d6ea2288dc8574f994bb281c2a784cf8 (diff)
downloadsamba-37c0312def0b0c1b3c4248bd8d797db15d88d772.tar.gz
samba-37c0312def0b0c1b3c4248bd8d797db15d88d772.tar.bz2
samba-37c0312def0b0c1b3c4248bd8d797db15d88d772.zip
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 used to be commit bd5cd502bf52164b95d7bfc026189e04988171db)
-rw-r--r--source3/include/smb.h10
-rw-r--r--source3/lib/slprintf.c30
-rw-r--r--source3/lib/util_file.c6
3 files changed, 44 insertions, 2 deletions
diff --git a/source3/include/smb.h b/source3/include/smb.h
index b8cd415ef9..854200e4cb 100644
--- a/source3/include/smb.h
+++ b/source3/include/smb.h
@@ -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;
diff --git a/source3/lib/slprintf.c b/source3/lib/slprintf.c
index a755bf1bc5..ed7113c865 100644
--- a/source3/lib/slprintf.c
+++ b/source3/lib/slprintf.c
@@ -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));
+}
diff --git a/source3/lib/util_file.c b/source3/lib/util_file.c
index 39c97d5c3f..d533e6428f 100644
--- a/source3/lib/util_file.c
+++ b/source3/lib/util_file.c
@@ -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);
}
+