MCPcopy Create free account
hub / github.com/LadybugDB/ladybug / linenoiseHistorySave

Function linenoiseHistorySave

tools/shell/linenoise.cpp:587–609  ·  view source on GitHub ↗

Save the history in the specified file. On success 0 is returned * otherwise -1 is returned. */

Source from the content-addressed store, hash-verified

585/* Save the history in the specified file. On success 0 is returned
586 * otherwise -1 is returned. */
587int linenoiseHistorySave(const char* filename) {
588#ifdef _WIN32
589 long old_umask = umask(_S_IREAD | _S_IWRITE);
590 FILE* fp = fopen(filename, "wb");
591#else
592 mode_t old_umask = umask(S_IXUSR | S_IRWXG | S_IRWXO);
593 FILE* fp = fopen(filename, "w");
594#endif
595 int j;
596
597 umask(old_umask);
598 if (fp == NULL)
599 return -1;
600#ifdef _WIN32
601 chmod(filename, _S_IREAD | _S_IWRITE);
602#else
603 chmod(filename, S_IRUSR | S_IWUSR);
604#endif
605 for (j = 0; j < history_len; j++)
606 fprintf(fp, "%s\n", history[j]);
607 fclose(fp);
608 return 0;
609}
610
611/* Load the history from the specified file. If the file does not exist
612 * zero is returned and no operation is performed.

Callers 1

runMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected