MCPcopy Create free account
hub / github.com/GaijinEntertainment/daScript / makeDirectory

Function makeDirectory

modules/dasSQLITE/sqlite/shell.c:5786–5820  ·  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

5784** SQLITE_ERROR otherwise.
5785*/
5786static int makeDirectory(
5787 const char *zFile
5788){
5789 char *zCopy = sqlite3_mprintf("%s", zFile);
5790 int rc = SQLITE_OK;
5791
5792 if( zCopy==0 ){
5793 rc = SQLITE_NOMEM;
5794 }else{
5795 int nCopy = (int)strlen(zCopy);
5796 int i = 1;
5797
5798 while( rc==SQLITE_OK ){
5799 struct stat sStat;
5800 int rc2;
5801
5802 for(; zCopy[i]!='/' && i<nCopy; i++);
5803 if( i==nCopy ) break;
5804 zCopy[i] = '\0';
5805
5806 rc2 = fileStat(zCopy, &sStat);
5807 if( rc2!=0 ){
5808 if( mkdir(zCopy, 0777) ) rc = SQLITE_ERROR;
5809 }else{
5810 if( !S_ISDIR(sStat.st_mode) ) rc = SQLITE_ERROR;
5811 }
5812 zCopy[i] = '/';
5813 i++;
5814 }
5815
5816 sqlite3_free(zCopy);
5817 }
5818
5819 return rc;
5820}
5821
5822/*
5823** 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