MCPcopy Create free account
hub / github.com/apache/cloudberry / readfile

Function readfile

src/bin/initdb/initdb.c:473–512  ·  view source on GitHub ↗

* get the lines from a text file */

Source from the content-addressed store, hash-verified

471 * get the lines from a text file
472 */
473static char **
474readfile(const char *path)
475{
476 char **result;
477 FILE *infile;
478 StringInfoData line;
479 int maxlines;
480 int n;
481
482 if ((infile = fopen(path, "r")) == NULL)
483 {
484 pg_log_error("could not open file \"%s\" for reading: %m", path);
485 exit(1);
486 }
487
488 initStringInfo(&line);
489
490 maxlines = 1024;
491 result = (char **) pg_malloc(maxlines * sizeof(char *));
492
493 n = 0;
494 while (pg_get_line_buf(infile, &line))
495 {
496 /* make sure there will be room for a trailing NULL pointer */
497 if (n >= maxlines - 1)
498 {
499 maxlines *= 2;
500 result = (char **) pg_realloc(result, maxlines * sizeof(char *));
501 }
502
503 result[n++] = pg_strdup(line.data);
504 }
505 result[n] = NULL;
506
507 pfree(line.data);
508
509 fclose(infile);
510
511 return result;
512}
513
514/*
515 * write an array of lines to a file

Callers 4

setup_configFunction · 0.70
bootstrap_template1Function · 0.70
setup_run_fileFunction · 0.70
setup_cdb_schemaFunction · 0.70

Calls 6

initStringInfoFunction · 0.85
pg_mallocFunction · 0.85
pg_get_line_bufFunction · 0.85
pg_reallocFunction · 0.85
pg_strdupFunction · 0.85
pfreeFunction · 0.50

Tested by

no test coverage detected