Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
concatenate getline.c at the end of xbt_str.c
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 26 Apr 2007 10:30:23 +0000 (10:30 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 26 Apr 2007 10:30:23 +0000 (10:30 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@3454 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/Makefile.am
src/xbt/getline.c [deleted file]
src/xbt/xbt_str.c

index 0b9ac73..b605530 100644 (file)
@@ -116,7 +116,7 @@ lib_LTLIBRARIES= libsimgrid.la libgras.la
 
 COMMON_SRC=\
   \
-  xbt/snprintf.c    xbt/getline.c      xbt/xbt_str.c                        \
+  xbt/snprintf.c    xbt/xbt_str.c                                            \
   xbt/ex.c                                                                   \
   \
   xbt_modinter.h    gras_modinter.h                                          \
diff --git a/src/xbt/getline.c b/src/xbt/getline.c
deleted file mode 100644 (file)
index ecf94b3..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-/* $Id$ */
-
-/* getline -- reimplementation of the GNU's getline() for other platforms   */
-
-/* Copyright (C) 2007 Martin Quinson. All rights reserved.                  */
-
-/* This program is free software; you can redistribute it and/or modify it
- * under the terms of the license (GNU LGPL) which comes with this package. */
-
-/** @brief  Reads an entire line.
- * 
- * Reads a line from the file specified by the file pointer passed
- * as parameter. This function is intead to replace the non-portable
- * GNU getline() function.
- * 
- * @param buf address to a string buffer. If null, it will be allocated to receive the read data. If not and if too short, it will be reallocated. Must be freed by caller.
- * @param n size of the buffer. Updated accordingly by the function.
- * @param stream File pointer to the file to read from.
- * @return The amount of chars read (or -1 on failure, ie on end of file condition)
- */
-#include "xbt/misc.h"
-#include "xbt/sysdep.h" /* headers of this function */
-#include "portable.h"
-
-#ifndef HAVE_GETLINE
-long getline(char **buf, size_t *n, FILE *stream) {
-   
-   int i, ch;
-   
-   if (!*buf) {
-     *buf = xbt_malloc(512);
-     *n = 512;
-   }
-   
-   if (feof(stream))
-     return (ssize_t)-1;
-   
-   for (i=0; (ch = fgetc(stream)) != EOF; i++)  {
-       
-      if (i >= (*n) + 1)
-       *buf = xbt_realloc(*buf, *n += 512);
-       
-      (*buf)[i] = ch;
-       
-      if ((*buf)[i] == '\n')  {
-        i++;
-        (*buf)[i] = '\0';
-        break;
-      }      
-   }
-      
-   if (i == *n) 
-     *buf = xbt_realloc(*buf, *n += 1);
-   
-   (*buf)[i] = '\0';
-
-   return (ssize_t)i;
-}
-
-#endif /* HAVE_GETLINE */
index f259b6a..ac798bf 100644 (file)
@@ -1,5 +1,8 @@
 
-/* Copyright (C) 2007 Malek Cherier. All rights reserved.                  */
+/* xbt_str.c - various helping functions to deal with strings               */
+
+/* Copyright (C) 2005-2007 Malek Cherier, Martin Quinson.                   */
+/* All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. 
@@ -133,3 +136,39 @@ trim(char* s, const char* char_list ){
     return ltrim(rtrim(s,char_list),char_list);
 }
    
+#ifndef HAVE_GETLINE
+long getline(char **buf, size_t *n, FILE *stream) {
+   
+   int i, ch;
+   
+   if (!*buf) {
+     *buf = xbt_malloc(512);
+     *n = 512;
+   }
+   
+   if (feof(stream))
+     return (ssize_t)-1;
+   
+   for (i=0; (ch = fgetc(stream)) != EOF; i++)  {
+       
+      if (i >= (*n) + 1)
+       *buf = xbt_realloc(*buf, *n += 512);
+       
+      (*buf)[i] = ch;
+       
+      if ((*buf)[i] == '\n')  {
+        i++;
+        (*buf)[i] = '\0';
+        break;
+      }      
+   }
+      
+   if (i == *n) 
+     *buf = xbt_realloc(*buf, *n += 1);
+   
+   (*buf)[i] = '\0';
+
+   return (ssize_t)i;
+}
+
+#endif /* HAVE_GETLINE */