Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Rename getline as xbt_getline.
authorArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Sun, 3 Feb 2013 23:01:00 +0000 (00:01 +0100)
committerArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Sun, 3 Feb 2013 23:01:00 +0000 (00:01 +0100)
ChangeLog
include/simgrid_config.h.in
src/mc/mc_checkpoint.c
src/mc/mc_global.c
src/mc/memory_map.c
src/msg/msg_actions.c
src/surf/storage.c
src/xbt/graph.c
src/xbt/xbt_replay.c
src/xbt/xbt_str.c
tools/tesh/tesh.c

index 1bd4768..4b2bc18 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,9 +1,12 @@
 SimGrid (3.10) NOT RELEASED; urgency=low
 
+ XBT:
+ * Our own implementation of getline is renamed xbt_getline.
+
  Java:
  * Reintegrate Java to the main archive as desynchronizing these
    package is not acceptable anymore (Java is now considered stable)
- * Bugfix: Task.setDataSize() only changed the C world, not the value 
+ * Bugfix: Task.setDataSize() only changed the C world, not the value
    cached in the Java world
 
 -- $date Da SimGrid team <simgrid-devel@lists.gforge.inria.fr>
index de9e3f1..06f6f53 100644 (file)
@@ -79,12 +79,8 @@ XBT_PUBLIC_DATA(xbt_dynar_t) sg_cmdline;
 @simgrid_need_vasprintf@
 
 #include <stdio.h>  /* FILE, getline if it exists  */
-
-/* Use that config to declare missing elements */
-#ifdef SIMGRID_NEED_GETLINE
-#include <stdlib.h> /* size_t */
-XBT_PUBLIC(long) getline(char **lineptr, size_t * n, FILE * stream);
-#endif
+#include <stdlib.h> /* size_t, ssize_t */
+XBT_PUBLIC(ssize_t) xbt_getline(char **lineptr, size_t * n, FILE * stream);
 
 #include <stdarg.h>
 
index 0cde216..d96dd72 100644 (file)
@@ -245,7 +245,7 @@ void get_libsimgrid_plt_section(){
   FILE *fp;
   char *line = NULL;            /* Temporal storage for each line that is readed */
   ssize_t read;                 /* Number of bytes readed */
-  size_t n = 0;                 /* Amount of bytes to read by getline */
+  size_t n = 0;                 /* Amount of bytes to read by xbt_getline */
 
   char *lfields[7];
   int i, plt_found = 0;
@@ -260,7 +260,7 @@ void get_libsimgrid_plt_section(){
     xbt_abort();
   }
 
-  while ((read = getline(&line, &n, fp)) != -1 && plt_found != 2) {
+  while ((read = xbt_getline(&line, &n, fp)) != -1 && plt_found != 2) {
 
     if(n == 0)
       continue;
@@ -310,7 +310,7 @@ void get_binary_plt_section(){
   FILE *fp;
   char *line = NULL;            /* Temporal storage for each line that is readed */
   ssize_t read;                 /* Number of bytes readed */
-  size_t n = 0;                 /* Amount of bytes to read by getline */
+  size_t n = 0;                 /* Amount of bytes to read by xbt_getline */
 
   char *lfields[7];
   int i, plt_found = 0;
@@ -325,7 +325,7 @@ void get_binary_plt_section(){
     xbt_abort();
   }
 
-  while ((read = getline(&line, &n, fp)) != -1 && plt_found != 2) {
+  while ((read = xbt_getline(&line, &n, fp)) != -1 && plt_found != 2) {
 
     if(n == 0)
       continue;
index cec559a..7043e09 100644 (file)
@@ -1050,7 +1050,7 @@ xbt_dict_t MC_get_location_list(const char *elf_file){
   int cursor_remove;
   xbt_dynar_t split = NULL;
 
-  while ((read = getline(&line, &n, fp)) != -1) {
+  while ((read = xbt_getline(&line, &n, fp)) != -1) {
 
     /* Wipeout the new line character */
     line[read - 1] = '\0';
@@ -1109,7 +1109,7 @@ xbt_dict_t MC_get_location_list(const char *elf_file){
       xbt_dynar_free(&split);
       free(loc_expr);
 
-      read = getline(&line, &n, fp);
+      read = xbt_getline(&line, &n, fp);
       if(read != -1){
         line[read - 1] = '\0';
         xbt_str_strip_spaces(line);
@@ -1174,12 +1174,12 @@ void MC_get_local_variables(const char *elf_file, xbt_dict_t location_list, xbt_
   int new_frame = 0, new_variable = 0;
   dw_frame_t variable_frame, subroutine_frame = NULL;
 
-  read = getline(&line, &n, fp);
+  read = xbt_getline(&line, &n, fp);
 
   while (read != -1) {
 
     if(n == 0){
-      read = getline(&line, &n, fp);
+      read = xbt_getline(&line, &n, fp);
       continue;
     }
  
@@ -1187,7 +1187,7 @@ void MC_get_local_variables(const char *elf_file, xbt_dict_t location_list, xbt_
     line[read - 1] = '\0';
    
     if(strlen(line) == 0){
-      read = getline(&line, &n, fp);
+      read = xbt_getline(&line, &n, fp);
       continue;
     }
 
@@ -1195,7 +1195,7 @@ void MC_get_local_variables(const char *elf_file, xbt_dict_t location_list, xbt_
     xbt_str_strip_spaces(line);
     
     if(line[0] != '<'){
-      read = getline(&line, &n, fp);
+      read = xbt_getline(&line, &n, fp);
       continue;
     }
     
@@ -1213,12 +1213,12 @@ void MC_get_local_variables(const char *elf_file, xbt_dict_t location_list, xbt_
       subprogram_start = strdup(strtok(NULL, "<"));
       xbt_str_rtrim(subprogram_start, ">:");
 
-      read = getline(&line, &n, fp);
+      read = xbt_getline(&line, &n, fp);
    
       while(read != -1){
 
         if(n == 0){
-          read = getline(&line, &n, fp);
+          read = xbt_getline(&line, &n, fp);
           continue;
         }
 
@@ -1226,7 +1226,7 @@ void MC_get_local_variables(const char *elf_file, xbt_dict_t location_list, xbt_
         line[read - 1] = '\0';
         
         if(strlen(line) == 0){
-          read = getline(&line, &n, fp);
+          read = xbt_getline(&line, &n, fp);
           continue;
         }
       
@@ -1309,7 +1309,7 @@ void MC_get_local_variables(const char *elf_file, xbt_dict_t location_list, xbt_
 
         }
 
-        read = getline(&line, &n, fp);
+        read = xbt_getline(&line, &n, fp);
 
       }
  
@@ -1335,12 +1335,12 @@ void MC_get_local_variables(const char *elf_file, xbt_dict_t location_list, xbt_
       origin = strdup(strtok(NULL, "<"));
       xbt_str_rtrim(origin, ">:");
       
-      read = getline(&line, &n, fp);
+      read = xbt_getline(&line, &n, fp);
       
       while(read != -1){
 
         if(n == 0){
-          read = getline(&line, &n, fp);
+          read = xbt_getline(&line, &n, fp);
           continue;
         }
 
@@ -1348,7 +1348,7 @@ void MC_get_local_variables(const char *elf_file, xbt_dict_t location_list, xbt_
         line[read - 1] = '\0'; 
 
         if(strlen(line) == 0){
-          read = getline(&line, &n, fp);
+          read = xbt_getline(&line, &n, fp);
           continue;
         }
        
@@ -1414,7 +1414,7 @@ void MC_get_local_variables(const char *elf_file, xbt_dict_t location_list, xbt_
         
         }
 
-        read = getline(&line, &n, fp);
+        read = xbt_getline(&line, &n, fp);
  
       }
 
@@ -1433,7 +1433,7 @@ void MC_get_local_variables(const char *elf_file, xbt_dict_t location_list, xbt_
       origin = strdup(strtok(NULL, "<"));
       xbt_str_rtrim(origin, ">:");
 
-      read = getline(&line, &n, fp);
+      read = xbt_getline(&line, &n, fp);
 
       while(read != -1){
 
@@ -1441,12 +1441,12 @@ void MC_get_local_variables(const char *elf_file, xbt_dict_t location_list, xbt_
         line[read - 1] = '\0'; 
 
         if(n == 0){
-          read = getline(&line, &n, fp);
+          read = xbt_getline(&line, &n, fp);
           continue;
         }
 
         if(strlen(line) == 0){
-          read = getline(&line, &n, fp);
+          read = xbt_getline(&line, &n, fp);
           continue;
         }
 
@@ -1478,13 +1478,13 @@ void MC_get_local_variables(const char *elf_file, xbt_dict_t location_list, xbt_
           subroutine_frame->high_pc = (void *)strtoul(xbt_dynar_get_as(split, 3, char *), NULL, 16);
         }
 
-        read = getline(&line, &n, fp);
+        read = xbt_getline(&line, &n, fp);
       
       }
 
     }else{
 
-      read = getline(&line, &n, fp);
+      read = xbt_getline(&line, &n, fp);
 
     }
 
@@ -1801,7 +1801,7 @@ static void MC_get_global_variables(char *elf_file){
 
   int type = strcmp(elf_file, xbt_binary_name); /* 0 = binary, other = libsimgrid */
 
-  while ((read = getline(&line, &n, fp)) != -1){
+  while ((read = xbt_getline(&line, &n, fp)) != -1){
 
     if(n == 0)
       continue;
index 25a49ca..1606b2d 100644 (file)
@@ -14,7 +14,7 @@ memory_map_t get_memory_map(void)
   FILE *fp;                     /* File pointer to process's proc maps file */
   char *line = NULL;            /* Temporal storage for each line that is readed */
   ssize_t read;                 /* Number of bytes readed */
-  size_t n = 0;                 /* Amount of bytes to read by getline */
+  size_t n = 0;                 /* Amount of bytes to read by xbt_getline */
   memory_map_t ret = NULL;      /* The memory map to return */
 
 /* The following variables are used during the parsing of the file "maps" */
@@ -35,7 +35,7 @@ memory_map_t get_memory_map(void)
   ret = xbt_new0(s_memory_map_t, 1);
 
   /* Read one line at the time, parse it and add it to the memory map to be returned */
-  while ((read = getline(&line, &n, fp)) != -1) {
+  while ((read = xbt_getline(&line, &n, fp)) != -1) {
 
     //fprintf(stderr,"%s", line);
 
index d8f2a72..885661e 100644 (file)
@@ -4,8 +4,6 @@
 /* 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. */
 
-#include "simgrid_config.h" //For getline, keep that include first
-
 #include "msg_private.h"
 #include "xbt/str.h"
 #include "xbt/dynar.h"
index 6c4e2ab..66abf8f 100644 (file)
@@ -593,7 +593,7 @@ static xbt_dict_t parse_storage_content(char *filename, unsigned long *used_size
 
   surf_stat_t content;
 
-  while ((read = getline(&line, &len, file)) != -1) {
+  while ((read = xbt_getline(&line, &len, file)) != -1) {
     if (read){
     content = xbt_new0(s_surf_stat_t,1);
     if(sscanf(line,"%s %d %s %s %ld %s %s %s",user_rights,&nb,user,group,&size,date,time,path)==8) {
index 50eee15..2c6603b 100644 (file)
@@ -6,7 +6,6 @@
 /* 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. */
 
-#include "simgrid_config.h" /* getline */
 #include <errno.h>
 #include <stdlib.h>
 #include "xbt/sysdep.h"
@@ -756,18 +755,18 @@ xbt_graph_t xbt_graph_load (const char *filename)
   //read the number of nodes
   size_t size;
   char *nnodes_str = NULL;
-  read = getline (&nnodes_str, &size, file);
+  read = xbt_getline (&nnodes_str, &size, file);
   if (read == -1)
-    THROWF(system_error, 0, "getline failed to read the number of nodes (errno = %d)", errno);
+    THROWF(system_error, 0, "xbt_getline failed to read the number of nodes (errno = %d)", errno);
   int i, nnodes = atoi (nnodes_str);
   free (nnodes_str);
 
   //read all nodes
   for (i = 0; i < nnodes; i++){
     char *node_str = NULL;
-    read = getline (&node_str, &size, file);
+    read = xbt_getline (&node_str, &size, file);
     if (read == -1)
-      THROWF(system_error, 0, "getline failed to read all nodes (errno = %d)", errno);
+      THROWF(system_error, 0, "xbt_getline failed to read all nodes (errno = %d)", errno);
     xbt_node_t n;
     char *name = xbt_strdup (node_str);
     xbt_str_subst (name, '\n', '\0', 0);
@@ -778,18 +777,18 @@ xbt_graph_t xbt_graph_load (const char *filename)
 
   //read the number of edges
   char *nedges_str = NULL;
-  read = getline (&nedges_str, &size, file);
+  read = xbt_getline (&nedges_str, &size, file);
   if (read == -1)
-    THROWF(system_error, 0, "getline failed to read the number of edges (errno = %d)", errno);
+    THROWF(system_error, 0, "xbt_getline failed to read the number of edges (errno = %d)", errno);
   int nedges = atoi (nedges_str);
   free (nedges_str);
 
   //read all edges
   for (i = 0; i < nedges; i++){
     char *edge_str = NULL, edge_id[200], node_source[200], node_target[200];
-    read = getline (&edge_str, &size, file);
+    read = xbt_getline (&edge_str, &size, file);
     if (read == -1)
-      THROWF(system_error, 0, "getline failed to read all edges (errno = %d)", errno);
+      THROWF(system_error, 0, "xbt_getline failed to read all edges (errno = %d)", errno);
     sscanf (edge_str, "%s %s %s", edge_id, node_source, node_target);
     free (edge_str);
     xbt_str_subst (edge_id, '\n', '\0', 0);
index cd6fa9a..10435c4 100644 (file)
@@ -3,7 +3,6 @@
 
 /* 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. */
-#include "simgrid_config.h" //For getline, keep that include first
 
 #include "internal_config.h"
 #include <errno.h>
@@ -53,7 +52,7 @@ const char **xbt_replay_reader_get(xbt_replay_reader_t reader)
 {
   ssize_t read;
   xbt_dynar_t d;
-  read = getline(&reader->line, &reader->line_len, reader->fp);
+  read = xbt_getline(&reader->line, &reader->line_len, reader->fp);
   //XBT_INFO("got from trace: %s",reader->line);
   reader->linenum++;
   if (read==-1)
@@ -181,7 +180,7 @@ static const char **action_get_action(char *name)
     }
     // Read lines until I reach something for me (which breaks in loop body)
     // or end of file reached
-    while (getline(&action_line, &action_len, action_fp) != -1) {
+    while (xbt_getline(&action_line, &action_len, action_fp) != -1) {
       // cleanup and split the string I just read
       char *comment = strchr(action_line, '#');
       if (comment != NULL)
index 4c361b5..5a2e5a6 100644 (file)
@@ -520,25 +520,31 @@ char *xbt_str_join_array(const char *const *strs, const char *sep)
   return res;
 }
 
-#if defined(SIMGRID_NEED_GETLINE) || defined(DOXYGEN)
 /** @brief Get a single line from the stream (reimplementation of the GNU getline)
  *
- * This is a redefinition of the GNU getline function, used on platforms where it does not exists.
+ * This is a redefinition of the GNU getline function, used on platforms where
+ * it does not exists.
  *
- * getline() reads an entire line from stream, storing the address of the buffer
- * containing the text into *buf.  The buffer is null-terminated and includes
- * the newline character, if one was found.
+ * xbt_getline() reads an entire line from stream, storing the address of the
+ * buffer containing the text into *buf.  The buffer is null-terminated and
+ * includes the newline character, if one was found.
  *
- * If *buf is NULL, then getline() will allocate a buffer for storing the line,
- * which should be freed by the user program.  Alternatively, before calling getline(),
- * *buf can contain a pointer to a malloc()-allocated buffer *n bytes in size.  If the buffer
- * is not large enough to hold the line, getline() resizes it with realloc(), updating *buf and *n
- * as necessary.  In either case, on a successful call, *buf and *n will be updated to
- * reflect the buffer address and allocated size respectively.
+ * If *buf is NULL, then xbt_getline() will allocate a buffer for storing the
+ * line, which should be freed by the user program.
+ *
+ * Alternatively, before calling xbt_getline(), *buf can contain a pointer to a
+ * malloc()-allocated buffer *n bytes in size.  If the buffer is not large
+ * enough to hold the line, xbt_getline() resizes it with realloc(), updating
+ * *buf and *n as necessary.
+ *
+ * In either case, on a successful call, *buf and *n will be updated to reflect
+ * the buffer address and allocated size respectively.
  */
-long getline(char **buf, size_t * n, FILE * stream)
+ssize_t xbt_getline(char **buf, size_t * n, FILE * stream)
 {
-
+#if !defined(SIMGRID_NEED_GETLINE)
+  return getline(buf, n, stream);
+#else
   size_t i;
   int ch;
 
@@ -570,10 +576,9 @@ long getline(char **buf, size_t * n, FILE * stream)
   (*buf)[i] = '\0';
 
   return (ssize_t) i;
+#endif
 }
 
-#endif                          /* HAVE_GETLINE */
-
 /*
  * Diff related functions
  *
index ae83f64..0c8b21b 100644 (file)
@@ -11,8 +11,6 @@
 #pragma hdrstop
 #endif
 
-#include "simgrid_config.h" //For getline, keep that include first
-
 #include "tesh.h"
 #include "xbt.h"
 
@@ -106,7 +104,7 @@ static void handle_suite(const char *filename, FILE * IN)
   buff = xbt_strbuff_new();
   rctx = rctx_new();
 
-  while (getline(&line, &len, IN) != -1) {
+  while (xbt_getline(&line, &len, IN) != -1) {
     line_num++;
 
     /* Count the line length while checking wheather it's blank */