MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / DBUGOpenFile

Function DBUGOpenFile

dbug/dbug.c:2079–2124  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2077 */
2078
2079static void DBUGOpenFile(CODE_STATE *cs,
2080 const char *name,const char *end,int append)
2081{
2082 REGISTER FILE *fp;
2083
2084 if (name != NULL)
2085 {
2086 if (end)
2087 {
2088 size_t len=end-name;
2089 memcpy(cs->stack->name, name, len);
2090 cs->stack->name[len]=0;
2091 }
2092 else
2093 strmov(cs->stack->name,name);
2094 name=cs->stack->name;
2095 if (strcmp(name, "-") == 0)
2096 {
2097 cs->stack->out_file= stdout;
2098 cs->stack->flags |= FLUSH_ON_WRITE;
2099 cs->stack->name[0]=0;
2100 }
2101 else
2102 {
2103 if (!Writable(name))
2104 {
2105 (void) fprintf(stderr, ERR_OPEN, cs->process, name);
2106 perror("");
2107 fflush(stderr);
2108 }
2109 else
2110 {
2111 if (!(fp= fopen(name, append ? "a+" : "w")))
2112 {
2113 (void) fprintf(stderr, ERR_OPEN, cs->process, name);
2114 perror("");
2115 fflush(stderr);
2116 }
2117 else
2118 {
2119 cs->stack->out_file= fp;
2120 }
2121 }
2122 }
2123 }
2124}
2125
2126/*
2127 * FUNCTION

Callers 1

DbugParseFunction · 0.85

Calls 3

strmovFunction · 0.85
WritableFunction · 0.85
perrorFunction · 0.85

Tested by

no test coverage detected