Author: jelmer
Date: 2005-09-15 19:52:13 +0000 (Thu, 15 Sep 2005)
New Revision: 10245

WebSVN: 
http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=10245

Log:
Get rid of XFILE in a few places. 
Add fdprintf() and vfdprintf() helper functions.

Modified:
   branches/SAMBA_4_0/source/lib/cmdline/readline.c
   branches/SAMBA_4_0/source/lib/credentials.c
   branches/SAMBA_4_0/source/lib/util_file.c
   branches/SAMBA_4_0/source/param/generic.c


Changeset:
Modified: branches/SAMBA_4_0/source/lib/cmdline/readline.c
===================================================================
--- branches/SAMBA_4_0/source/lib/cmdline/readline.c    2005-09-15 18:50:44 UTC 
(rev 10244)
+++ branches/SAMBA_4_0/source/lib/cmdline/readline.c    2005-09-15 19:52:13 UTC 
(rev 10245)
@@ -59,7 +59,7 @@
        fd_set fds;
        static pstring line;
        struct timeval timeout;
-       int fd = x_fileno(x_stdin);
+       int fd = STDIN_FILENO;
        char *ret;
 
        do_debug("%s", prompt);
@@ -88,7 +88,7 @@
                   char **(completion_fn)(const char *text, int start, int end))
 {
 #if HAVE_LIBREADLINE
-       if (isatty(x_fileno(x_stdin))) {
+       if (isatty(STDIN_FILENO)) {
                char *ret;
 
                /* Aargh!  Readline does bizzare things with the terminal width

Modified: branches/SAMBA_4_0/source/lib/credentials.c
===================================================================
--- branches/SAMBA_4_0/source/lib/credentials.c 2005-09-15 18:50:44 UTC (rev 
10244)
+++ branches/SAMBA_4_0/source/lib/credentials.c 2005-09-15 19:52:13 UTC (rev 
10245)
@@ -671,37 +671,30 @@
 
 BOOL cli_credentials_parse_file(struct cli_credentials *cred, const char 
*file, enum credentials_obtained obtained) 
 {
-       XFILE *auth;
-       char buf[128];
        uint16_t len = 0;
        char *ptr, *val, *param;
+       char **lines;
+       int i, numlines;
 
-       if ((auth=x_fopen(file, O_RDONLY, 0)) == NULL)
+       lines = file_lines_load(file, &numlines, NULL);
+
+       if (lines == NULL)
        {
                /* fail if we can't open the credentials file */
                d_printf("ERROR: Unable to open credentials file!\n");
                return False;
        }
 
-       while (!x_feof(auth))
-       {
-               /* get a line from the file */
-               if (!x_fgets(buf, sizeof(buf), auth))
-                       continue;
-               len = strlen(buf);
+       for (i = 0; i < numlines; i++) {
+               len = strlen(lines[i]);
 
-               if ((len) && (buf[len-1]=='\n'))
-               {
-                       buf[len-1] = '\0';
-                       len--;
-               }
                if (len == 0)
                        continue;
 
                /* break up the line into parameter & value.
                 * will need to eat a little whitespace possibly */
-               param = buf;
-               if (!(ptr = strchr_m (buf, '=')))
+               param = lines[i];
+               if (!(ptr = strchr_m (lines[i], '=')))
                        continue;
 
                val = ptr+1;
@@ -720,10 +713,11 @@
                } else if (strwicmp("realm", param) == 0) {
                        cli_credentials_set_realm(cred, val, obtained);
                }
-               memset(buf, 0, sizeof(buf));
+               memset(lines[i], 0, len);
        }
 
-       x_fclose(auth);
+       talloc_free(lines);
+
        return True;
 }
 

Modified: branches/SAMBA_4_0/source/lib/util_file.c
===================================================================
--- branches/SAMBA_4_0/source/lib/util_file.c   2005-09-15 18:50:44 UTC (rev 
10244)
+++ branches/SAMBA_4_0/source/lib/util_file.c   2005-09-15 19:52:13 UTC (rev 
10245)
@@ -397,3 +397,29 @@
        struct stat st;
        return (stat(path, &st) == 0);
 }
+
+int vfdprintf(int fd, const char *format, va_list ap) 
+{
+       char *p;
+       int len, ret;
+       va_list ap2;
+
+       VA_COPY(ap2, ap);
+
+       len = vasprintf(&p, format, ap2);
+       if (len <= 0) return len;
+       ret = write(fd, p, len);
+       SAFE_FREE(p);
+       return ret;
+}
+
+int fdprintf(int fd, const char *format, ...) _PRINTF_ATTRIBUTE(2,3)
+{
+       va_list ap;
+       int ret;
+
+       va_start(ap, format);
+       ret = vfdprintf(fd, format, ap);
+       va_end(ap);
+       return ret;
+}

Modified: branches/SAMBA_4_0/source/param/generic.c
===================================================================
--- branches/SAMBA_4_0/source/param/generic.c   2005-09-15 18:50:44 UTC (rev 
10244)
+++ branches/SAMBA_4_0/source/param/generic.c   2005-09-15 19:52:13 UTC (rev 
10245)
@@ -242,28 +242,28 @@
 
 int param_write(struct param_context *ctx, const char *fn)
 {
-       XFILE *file;
+       int file;
        struct param_section *section;
 
        if (fn == NULL || ctx == NULL)
                return -1;
 
-       file = x_fopen(fn, O_WRONLY|O_CREAT, 0755);
+       file = open(fn, O_WRONLY|O_CREAT, 0755);
 
-       if (file == NULL)
+       if (file == -1)
                return -1;
        
        for (section = ctx->sections; section; section = section->next) {
                struct param *param;
                
-               x_fprintf(file, "[%s]\n", section->name);
+               fdprintf(file, "[%s]\n", section->name);
                for (param = section->parameters; param; param = param->next) {
-                       x_fprintf(file, "\t%s = %s\n", param->name, 
param->value);
+                       fdprintf(file, "\t%s = %s\n", param->name, 
param->value);
                }
-               x_fprintf(file, "\n");
+               fdprintf(file, "\n");
        }
 
-       x_fclose(file);
+       close(file);
 
        return 0;
 }

Reply via email to