From 7e741c018ba34742ccfdbf842299d711521dbf8f Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Mon, 4 Feb 2013 00:01:00 +0100 Subject: [PATCH] Rename getline as xbt_getline. --- ChangeLog | 5 ++++- include/simgrid_config.h.in | 8 ++------ src/mc/mc_checkpoint.c | 8 ++++---- src/mc/mc_global.c | 40 ++++++++++++++++++------------------- src/mc/memory_map.c | 4 ++-- src/msg/msg_actions.c | 2 -- src/surf/storage.c | 2 +- src/xbt/graph.c | 17 ++++++++-------- src/xbt/xbt_replay.c | 5 ++--- src/xbt/xbt_str.c | 35 ++++++++++++++++++-------------- tools/tesh/tesh.c | 4 +--- 11 files changed, 64 insertions(+), 66 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1bd4768c67..4b2bc1899a 100644 --- 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 diff --git a/include/simgrid_config.h.in b/include/simgrid_config.h.in index de9e3f1750..06f6f53134 100644 --- a/include/simgrid_config.h.in +++ b/include/simgrid_config.h.in @@ -79,12 +79,8 @@ XBT_PUBLIC_DATA(xbt_dynar_t) sg_cmdline; @simgrid_need_vasprintf@ #include /* FILE, getline if it exists */ - -/* Use that config to declare missing elements */ -#ifdef SIMGRID_NEED_GETLINE -#include /* size_t */ -XBT_PUBLIC(long) getline(char **lineptr, size_t * n, FILE * stream); -#endif +#include /* size_t, ssize_t */ +XBT_PUBLIC(ssize_t) xbt_getline(char **lineptr, size_t * n, FILE * stream); #include diff --git a/src/mc/mc_checkpoint.c b/src/mc/mc_checkpoint.c index 0cde2167f2..d96dd72e4b 100644 --- a/src/mc/mc_checkpoint.c +++ b/src/mc/mc_checkpoint.c @@ -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; diff --git a/src/mc/mc_global.c b/src/mc/mc_global.c index cec559a6c2..7043e09b49 100644 --- a/src/mc/mc_global.c +++ b/src/mc/mc_global.c @@ -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; diff --git a/src/mc/memory_map.c b/src/mc/memory_map.c index 25a49ca511..1606b2d4b0 100644 --- a/src/mc/memory_map.c +++ b/src/mc/memory_map.c @@ -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); diff --git a/src/msg/msg_actions.c b/src/msg/msg_actions.c index d8f2a726a9..885661ef9b 100644 --- a/src/msg/msg_actions.c +++ b/src/msg/msg_actions.c @@ -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" diff --git a/src/surf/storage.c b/src/surf/storage.c index 6c4e2ab446..66abf8fd7c 100644 --- a/src/surf/storage.c +++ b/src/surf/storage.c @@ -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) { diff --git a/src/xbt/graph.c b/src/xbt/graph.c index 50eee15c2d..2c6603b621 100644 --- a/src/xbt/graph.c +++ b/src/xbt/graph.c @@ -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 #include #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); diff --git a/src/xbt/xbt_replay.c b/src/xbt/xbt_replay.c index cd6fa9acd8..10435c4cfe 100644 --- a/src/xbt/xbt_replay.c +++ b/src/xbt/xbt_replay.c @@ -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 @@ -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) diff --git a/src/xbt/xbt_str.c b/src/xbt/xbt_str.c index 4c361b594f..5a2e5a62bb 100644 --- a/src/xbt/xbt_str.c +++ b/src/xbt/xbt_str.c @@ -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 * diff --git a/tools/tesh/tesh.c b/tools/tesh/tesh.c index ae83f641ff..0c8b21b44e 100644 --- a/tools/tesh/tesh.c +++ b/tools/tesh/tesh.c @@ -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 */ -- 2.20.1