MP-Gadget  5.0.1.dev1-76bc7d4726-dirty
Functions
string.h File Reference
#include <stdarg.h>
Include dependency graph for string.h:

Go to the source code of this file.

Functions

char * fastpm_file_get_content (const char *filename)
 
char * fastpm_strdup (const char *str)
 
char * fastpm_strdup_printf (const char *fmt,...)
 
char * fastpm_strdup_vprintf (const char *fmt, va_list va)
 
void fastpm_path_ensure_dirname (const char *path)
 

Function Documentation

◆ fastpm_file_get_content()

char* fastpm_file_get_content ( const char *  filename)

Definition at line 14 of file string.c.

15 {
16  FILE * fp = fopen(filename, "r");
17  if(!fp) return NULL;
18 
19  fseek(fp, 0, SEEK_END);
20  size_t file_length = ftell(fp);
21 
22  char * buf = ta_malloc2(filename, char, file_length + 1);
23  fseek(fp, 0, SEEK_SET);
24  file_length = fread(buf, 1, file_length, fp);
25  fclose(fp);
26  buf[file_length] = 0;
27  return buf;
28 }
#define ta_malloc2(name, type, nele)
Definition: mymalloc.h:26

References ta_malloc2.

Referenced by hci_query_filesystem(), and param_parse_file().

Here is the caller graph for this function:

◆ fastpm_path_ensure_dirname()

void fastpm_path_ensure_dirname ( const char *  path)

Definition at line 70 of file string.c.

71 {
72  int i = strlen(path);
73  char * dup = ta_malloc("dirname", char, strlen(path) + 1);
74  strcpy(dup, path);
75  dup[strlen(path)]='\0';
76  char * p;
77  for(p = i + dup; p >= dup && *p != '/'; p --) {
78  continue;
79  }
80  /* plain file name in current directory */
81  if(p < dup) return;
82 
83  /* p == '/', so set it to NULL, dup is the dirname */
84  *p = 0;
85  _mkdir(dup);
86  myfree(dup);
87 }
#define ta_malloc(name, type, nele)
Definition: mymalloc.h:25
#define myfree(x)
Definition: mymalloc.h:19
static void _mkdir(const char *dir)
Definition: string.c:90

References _mkdir(), myfree, and ta_malloc.

Referenced by open_outputfiles().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fastpm_strdup()

char* fastpm_strdup ( const char *  str)

Definition at line 31 of file string.c.

32 {
33  size_t N = strlen(str);
34  char * d = ta_malloc("strdup", char, N + 1);
35  strcpy(d, str);
36  d[N] = '\0';
37  return d;
38 }

References ta_malloc.

Referenced by OutputListAction(), param_declare_string(), param_format_value(), param_set_from_string(), and parse_enum().

Here is the caller graph for this function:

◆ fastpm_strdup_printf()

char* fastpm_strdup_printf ( const char *  fmt,
  ... 
)

Definition at line 41 of file string.c.

42 {
43  va_list va;
44  va_start(va, fmt);
45  char * buf = fastpm_strdup_vprintf(fmt, va);
46  va_end(va);
47  return buf;
48 }
char * fastpm_strdup_vprintf(const char *fmt, va_list va)
Definition: string.c:51

References fastpm_strdup_vprintf().

Referenced by begrun(), dump_snapshot(), exists(), find_last_snapnum(), fof_save_particles(), hci_query_filesystem(), open_outputfiles(), petaio_get_snapshot_fname(), powerspectrum_nu_save(), powerspectrum_save(), run_gravity_test(), setup_glass(), touch(), and write_checkpoint().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fastpm_strdup_vprintf()

char* fastpm_strdup_vprintf ( const char *  fmt,
va_list  va 
)

Definition at line 51 of file string.c.

52 {
53  va_list va2;
54  va_copy(va2, va);
55  /* This relies on a good LIBC vsprintf that returns the number of char */
56  char buf0[128];
57  size_t N = vsnprintf(buf0, 1, fmt, va);
58 
59  char * buf = ta_malloc("strdup_vprintf", char, N + 100);
60  vsnprintf(buf, N + 1, fmt, va2);
61  buf[N + 1] = 0;
62  va_end(va2);
63  return buf;
64 }

References ta_malloc.

Referenced by fastpm_strdup_printf(), and report_detailed_memory_usage().

Here is the caller graph for this function: