]> git.ozlabs.org Git - ccan-lca-2011.git/commitdiff
merge
authorRusty Russell <rusty@rustcorp.com.au>
Mon, 4 Aug 2008 03:47:09 +0000 (13:47 +1000)
committerRusty Russell <rusty@rustcorp.com.au>
Mon, 4 Aug 2008 03:47:09 +0000 (13:47 +1000)
ccan/string/string.c
ccan/string/string.h
tools/_infotojson/infotojson.c
tools/doc_extract.c
tools/grab_file.c
tools/tools.h

index b1de8eda915bbf3ee81fc2e9f1df96603eb6084b..9182ac0650fb7b9c94ba72aa12872ca7f44310d0 100644 (file)
@@ -6,6 +6,10 @@
 #include <stdlib.h>
 #include "string.h"
 #include "talloc/talloc.h"
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
 
 char **strsplit(const void *ctx, const char *string, const char *delims,
                 unsigned int *nump)
@@ -42,3 +46,51 @@ char *strjoin(const void *ctx, char *strings[], const char *delim)
        }
        return ret;
 }
+
+static int close_no_errno(int fd)
+{
+       int ret = 0, serrno = errno;
+       if (close(fd) < 0)
+               ret = errno;
+       errno = serrno;
+       return ret;
+}
+
+void *grab_fd(const void *ctx, int fd)
+{
+       int ret;
+       unsigned int max = 16384, size = 0;
+       char *buffer;
+
+       buffer = talloc_array(ctx, char, max+1);
+       while ((ret = read(fd, buffer + size, max - size)) > 0) {
+               size += ret;
+               if (size == max)
+                       buffer = talloc_realloc(ctx, buffer, char, max*=2 + 1);
+       }
+       if (ret < 0) {
+               talloc_free(buffer);
+               buffer = NULL;
+       } else
+               buffer[size] = '\0';
+
+       return buffer;
+}
+
+void *grab_file(const void *ctx, const char *filename)
+{
+       int fd;
+       char *buffer;
+
+       if (streq(filename, "-"))
+               fd = dup(STDIN_FILENO);
+       else
+               fd = open(filename, O_RDONLY, 0);
+
+       if (fd < 0)
+               return NULL;
+
+       buffer = grab_fd(ctx, fd);
+       close_no_errno(fd);
+       return buffer;
+}
index b2cd814c1bde23179f53903084a8f271bb549e17..14a9c2c8fdba86eedbb4c0845c5cd24d69035b34 100644 (file)
@@ -102,4 +102,8 @@ char **strsplit(const void *ctx, const char *string, const char *delims,
  *     }
  */
 char *strjoin(const void *ctx, char *strings[], const char *delim);
+
+void *grab_fd(const void *ctx, int fd);
+
+void *grab_file(const void *ctx, const char *filename);
 #endif /* CCAN_STRING_H */
index 86769bbccc59c1ac215773413dfbae570d930fcb..460cb7fe1cd815154dca70ed4162ce16b72eb090 100644 (file)
@@ -1,36 +1,6 @@
 /* This extract info from _info.c and create json file and also optionally store to db */
 #include "infotojson.h"
 
-/* This version adds one byte (for nul term) */
-static void *grab_file(void *ctx, const char *filename)
-{
-       unsigned int max = 16384, size = 0;
-       int ret, fd;
-       char *buffer;
-
-       if (streq(filename, "-"))
-               fd = dup(STDIN_FILENO);
-       else
-               fd = open(filename, O_RDONLY, 0);
-
-       if (fd < 0)
-               return NULL;
-
-       buffer = talloc_array(ctx, char, max+1);
-       while ((ret = read(fd, buffer + size, max - size)) > 0) {
-               size += ret;
-               if (size == max)
-                       buffer = talloc_realloc(ctx, buffer, char, max*=2 + 1);
-       }
-       if (ret < 0) {
-               talloc_free(buffer);
-               buffer = NULL;
-       } else
-               buffer[size] = '\0';
-       close(fd);
-       return buffer;
-}
-
 /*creating json structure for storing to file/db*/
 static struct json *createjson(char **infofile, char *author)
 {
@@ -56,10 +26,6 @@ static struct json *createjson(char **infofile, char *author)
         if (!jsonobj->module)
                errx(1, "talloc error");
                
-       //jsonobj->module = (char *)palloc(sizeof(char) * (modulename - 1));
-       //strncpy(jsonobj->module, infofile[0], modulename - 1);
-       //jsonobj->module[modulename - 1] = '\0';
-
        jsonobj->title = infofile[0];
        jsonobj->desc = &infofile[1];
        
index aa3f2206cc3bace91b18b657690d2d282084a9a1..b70325ea47f51a00f7db114024bbbc24e2089920 100644 (file)
 #include "talloc/talloc.h"
 #include "string/string.h"
 
-/* This version adds one byte (for nul term) */
-static void *grab_file(void *ctx, const char *filename)
-{
-       unsigned int max = 16384, size = 0;
-       int ret, fd;
-       char *buffer;
-
-       if (streq(filename, "-"))
-               fd = dup(STDIN_FILENO);
-       else
-               fd = open(filename, O_RDONLY, 0);
-
-       if (fd < 0)
-               return NULL;
-
-       buffer = talloc_array(ctx, char, max+1);
-       while ((ret = read(fd, buffer + size, max - size)) > 0) {
-               size += ret;
-               if (size == max)
-                       buffer = talloc_realloc(ctx, buffer, char, max*=2 + 1);
-       }
-       if (ret < 0) {
-               talloc_free(buffer);
-               buffer = NULL;
-       } else
-               buffer[size] = '\0';
-       close(fd);
-       return buffer;
-}
 
 int main(int argc, char *argv[])
 {
index 8bd18f22553949a14d1fddfabd177018e412d172..5a2ff69b50ac1ab9a3304783ff03dc56e300cdc8 100644 (file)
@@ -7,16 +7,16 @@
 #include <unistd.h>
 #include <errno.h>
 
-static int close_no_errno(int fd)
+/*static int close_no_errno(int fd)
 {
        int ret = 0, serrno = errno;
        if (close(fd) < 0)
                ret = errno;
        errno = serrno;
        return ret;
-}
+}*/
 
-void *grab_fd(const void *ctx, int fd)
+/*void *grab_fd(const void *ctx, int fd)
 {
        int ret;
        unsigned int max = 16384, size = 0;
@@ -35,10 +35,10 @@ void *grab_fd(const void *ctx, int fd)
                buffer[size] = '\0';
 
        return buffer;
-}
+}*/
 
 /* This version adds one byte (for nul term) */
-void *grab_file(const void *ctx, const char *filename)
+/*void *grab_file(const void *ctx, const char *filename)
 {
        int fd;
        char *buffer;
@@ -54,5 +54,5 @@ void *grab_file(const void *ctx, const char *filename)
        buffer = grab_fd(ctx, fd);
        close_no_errno(fd);
        return buffer;
-}
+}*/
 
index fff962c7eb033cf08f7fe1939e2f231bef8caf74..f07627ebee99f4e10b62524c16be72a69f492d7c 100644 (file)
@@ -5,8 +5,5 @@
 
 char **get_deps(const void *ctx, const char *dir);
 
-void *grab_fd(const void *ctx, int fd);
-void *grab_file(const void *ctx, const char *filename);
-
 #endif /* CCAN_TOOLS_H */