MCPcopy Create free account
hub / github.com/audacity/audacity / makeDirectory

Function makeDirectory

lib-src/sqlite/shell.c:2422–2456  ·  view source on GitHub ↗

** Argument zFile is the name of a file that will be created and/or written ** by SQL function writefile(). This function ensures that the directory ** zFile will be written to exists, creating it if required. The permissions ** for any path components created by this function are set in accordance ** with the current umask. ** ** If an OOM condition is encountered, SQLITE_NOMEM is returned. Other

Source from the content-addressed store, hash-verified

2420** SQLITE_ERROR otherwise.
2421*/
2422static int makeDirectory(
2423 const char *zFile
2424){
2425 char *zCopy = sqlite3_mprintf("%s", zFile);
2426 int rc = SQLITE_OK;
2427
2428 if( zCopy==0 ){
2429 rc = SQLITE_NOMEM;
2430 }else{
2431 int nCopy = (int)strlen(zCopy);
2432 int i = 1;
2433
2434 while( rc==SQLITE_OK ){
2435 struct stat sStat;
2436 int rc2;
2437
2438 for(; zCopy[i]!='/' && i<nCopy; i++);
2439 if( i==nCopy ) break;
2440 zCopy[i] = '\0';
2441
2442 rc2 = fileStat(zCopy, &sStat);
2443 if( rc2!=0 ){
2444 if( mkdir(zCopy, 0777) ) rc = SQLITE_ERROR;
2445 }else{
2446 if( !S_ISDIR(sStat.st_mode) ) rc = SQLITE_ERROR;
2447 }
2448 zCopy[i] = '/';
2449 i++;
2450 }
2451
2452 sqlite3_free(zCopy);
2453 }
2454
2455 return rc;
2456}
2457
2458/*
2459** This function does the work for the writefile() UDF. Refer to

Callers 1

writefileFuncFunction · 0.85

Calls 1

fileStatFunction · 0.85

Tested by

no test coverage detected