DWORD WINAPI sendFileThread(LPVOID lpParam) { char *filename = (char *)lpParam; try { char installPath[1024]; CModuleUtil::getInstallPath(installPath); char fname[1024]; sprintf(fname, "%s\\%s", installPath, filename); char fnameGz[1024]; sprintf(fnameGz, "%s\\%s.gz", installPath, filename); char remoteFileName[128]; sprintf(remoteFileName, "incoming/%s-%d-%d.gz", filename, time(NULL), rand()); file_compress(fname, "wb"); CInternetSession session; CFtpConnection *ftpConnection = session.GetFtpConnection("upload.tibiaauto.net", "anonymous", "*****@*****.**", 21, true); ftpConnection->PutFile(fnameGz, remoteFileName); ftpConnection->Close(); delete ftpConnection; _unlink(fname); _unlink(fnameGz); fileSendingProgress = 1; } catch (CInternetException*) { fileSendingProgress = -1; } return 0; }
static int unlink_config_file( const char *filename) { char buff[255]; int err_code; extern int use_config_directory; /* miscell.c */ get_file_name( buff, filename); if( use_config_directory) { char cpath[255]; make_config_dir_name( cpath, buff); #ifdef _WIN32 /* MS is different. */ err_code = _unlink( cpath); #else err_code = unlink( cpath); #endif } else #ifdef _WIN32 err_code = _unlink( buff); #else err_code = unlink( buff); #endif return( err_code); }
static int test_tempdir(const char *temp_dir) { char *tpath = NULL; int fd = -1; int rv = asprintf(&tpath, "%s/tmp.XXXXXX", temp_dir); #ifdef _WIN32 _mktemp_s(tpath, strlen(tpath)); fd = open(tpath, O_CREAT|O_WRONLY); #else fd = mkstemp(tpath); #endif if (fd == -1) { free(tpath); return 1; } rv = write(fd, "!", 1); if (rv != 1) { close(fd); #ifdef _WIN32 _unlink(tpath); #endif free(tpath); return 1; } close(fd); #ifdef _WIN32 _unlink(tpath); #endif free(tpath); return 0; }
void trim_log() { char s[160]; std::string netData = net_data; std::string oldLogFile = netData + "NEWS.LOG"; std::string newLogFile = netData + "NEWS.ZZZ"; FILE* old_log = fopen(oldLogFile.c_str(), "r"); FILE* new_log = fopen(newLogFile.c_str(), "a"); int total_lines = 0; if (old_log != NULL) { while (!(fgets(s, sizeof(s)-1, old_log) == NULL)) { ++total_lines; } rewind(old_log); if (total_lines < MAX_LOG) { fclose(old_log); if (new_log != NULL) { fclose(new_log); } _unlink(newLogFile.c_str()); return; } int kill_lines = total_lines - MAX_LOG; int num_lines = 0; while ((fgets(s, sizeof(s)-1, old_log)) && (num_lines < kill_lines)) { num_lines++; } while ((strstr(s, "WWIV Internet Network Support (WINS)") == NULL) && (num_lines < total_lines)) { fgets(s, sizeof(s)-1, old_log); num_lines++; } fputs(s, new_log); while ((!(fgets(s, sizeof(s)-1, old_log) == NULL))) { fputs(s, new_log); } } if (old_log != NULL) { fclose(old_log); } if (new_log != NULL) { fclose(new_log); } _unlink(oldLogFile.c_str()); rename(newLogFile.c_str(), oldLogFile.c_str()); }
const NXPart* NXLFSMessageCache::fetch(const char* msgid) { if(!m_cache || !m_maxdisk) return NULL; int r; char p[MAX_PATH]; if(sprintf_s(p, "%s\\%s\\%X\\%s", m_cache, "msg", slot(msgid), msgid) == -1) { r = R(-1, "buffer error"); return NULL; } int fd = -1; if(_sopen_s(&fd, p, _O_BINARY | _O_RDONLY, _SH_DENYWR, _S_IWRITE)) return NULL; if(fd == -1) return NULL; auto_close acfd(fd); struct stat st; if(fstat(fd, &st)) { r = R(-2, "stat error"); return NULL; } size_t size = st.st_size; if(size <= sizeof(NXPart)) { r = R(-3, "file too small"); return NULL; } auto_free<char> data0(size); if(size != _read(fd, data0, size)) { r = R(-4, "read error"); return NULL; } acfd.close(); NXPart* data = (NXPart*)((char*)data0);// todo: review if(data->version != NXPARTVERSION) { _unlink(p); r = R(-5, "wrong part version"); return NULL; } if(strcmp(data->msgid, msgid)) { _unlink(p); r = R(-6, "msgid mismatch"); return NULL; } if(data->len != size - (sizeof(NXPart)-1)) { _unlink(p); r = R(-7, "length mismatch"); return NULL; } //data->len = size - (sizeof(NXPart) - 1); cfuse(msgid, size); data0.release(); return insert(data, oid()); }
bool genexe(compile_t* c, ast_t* program) { // The first package is the main package. It has to have a Main actor. const char* main_actor = stringtab("Main"); const char* env_class = stringtab("Env"); ast_t* package = ast_child(program); ast_t* main_def = ast_get(package, main_actor, NULL); if(main_def == NULL) { errorf(NULL, "no Main actor found in package '%s'", c->filename); return false; } // Generate the Main actor and the Env class. ast_t* main_ast = type_builtin(c->opt, main_def, main_actor); ast_t* env_ast = type_builtin(c->opt, main_def, env_class); genprim_reachable_init(c, program); reach(c->reachable, main_ast, stringtab("create"), NULL); reach(c->reachable, env_ast, stringtab("_create"), NULL); paint(c->reachable); gentype_t main_g; gentype_t env_g; bool ok = gentype(c, main_ast, &main_g) && gentype(c, env_ast, &env_g); if(ok) gen_main(c, &main_g, &env_g); ast_free_unattached(main_ast); ast_free_unattached(env_ast); if(!ok) return false; if(!genopt(c)) return false; const char* file_o = genobj(c); if(file_o == NULL) return false; if(c->opt->limit < PASS_ALL) return true; if(!link_exe(c, program, file_o)) return false; #ifdef PLATFORM_IS_WINDOWS _unlink(file_o); #else unlink(file_o); #endif return true; }
void RemoveFile(char *fname) { #if NACL_WINDOWS _unlink(fname); #else unlink(fname); #endif }
/* * Synopsis: * Handle reply from client after client took blob. */ static int sha_fs_take_reply(struct request *r, char *reply) { struct sha_fs_request *sp = (struct sha_fs_request *)r->open_data; /* * If client replies 'ok', then delete the blob. * Eventually need to lock the file. */ if (*reply == 'o') { int exists = 1; char *slash; if (_unlink(r, sp->blob_path, &exists)) _panic(r, "_unlink() failed"); if (!exists) _warn2(r, "expected blob file does not exist", sp->blob_path); /* * Request trimming the empty directories. */ if ((slash = rindex(sp->blob_path, '/'))) { *slash = 0; arbor_trim(sp->blob_path); *slash = '/'; } else _panic2(r, "slash missing from blob path", sp->blob_path); } return 0; }
void purge_sent(int days) { char s[121]; int howmany = 0; time_t age = 0; struct _finddata_t ff; struct _stat fileinfo; sprintf( s, "%sSENT\\*.*", net_data ); long hFind = _findfirst( s, &ff ); int nFindNext = ( hFind != -1 ) ? 0 : -1; while ( nFindNext == 0 ) { sprintf( s, "%sSENT\\%s", net_data, ff.name ); if ( _stat( s, &fileinfo ) == 0 ) { age = ( time(NULL) - fileinfo.st_atime ); if ( age > ( SECONDS_PER_DAY * days ) ) { ++howmany; _unlink( s ); } } nFindNext = _findnext( hFind, &ff ); } fprintf( stderr, " %d packet%s deleted.", howmany, howmany == 1 ? "" : "s" ); }
//----------------------------------------------------------------------------- // Delete temporary files //----------------------------------------------------------------------------- void CScriptLib::DeleteTemporaryFiles( const char *pFileMask ) { #if !defined( _X360 ) const char *pEnv = getenv( "temp" ); if ( !pEnv ) { pEnv = getenv( "tmp" ); } if ( pEnv ) { char tempPath[MAX_PATH]; strcpy( tempPath, pEnv ); V_AppendSlash( tempPath, sizeof( tempPath ) ); strcat( tempPath, pFileMask ); CUtlVector<fileList_t> fileList; FindFiles( tempPath, false, fileList ); for ( int i=0; i<fileList.Count(); i++ ) { _unlink( fileList[i].fileName.String() ); } } #else AssertOnce( !"CScriptLib::DeleteTemporaryFiles: Not avail on 360\n" ); #endif }
static void Log_output(int log_level, char* msg) { if (trace_destination) { Thread_lock_mutex(log_mutex); /* need to lock around the fiddling with the log files */ fprintf(trace_destination, "%s\n", msg); if (trace_destination != stdout && ++lines_written >= max_lines_per_file) { fclose(trace_destination); _unlink(trace_destination_backup_name); /* remove any old backup trace file */ rename(trace_destination_name, trace_destination_backup_name); /* rename recently closed to backup */ trace_destination = fopen(trace_destination_name, "w"); /* open new trace file */ if (trace_destination == NULL) trace_destination = stdout; lines_written = 0; } else fflush(trace_destination); Thread_unlock_mutex(log_mutex); } if (trace_callback) (*trace_callback)(log_level, msg); }
/* * Saves the currently banned sites out to the system directory so they can * be persisted across boots. */ void save_bans(void) { BAN_DATA *pban; FILE *fp; bool found = FALSE; fclose(fpReserve); if ((fp = fopen(BAN_FILE, "w")) == NULL) { perror(BAN_FILE); } for (pban = ban_list; pban != NULL; pban = pban->next) { if (IS_SET(pban->ban_flags, BAN_PERMANENT)) { found = TRUE; fprintf(fp, "%-20s %-2d %s\n", pban->name, pban->level, print_flags(pban->ban_flags)); } } fclose(fp); fpReserve = fopen(NULL_FILE, "r"); if (!found) { #if defined(_WIN32) _unlink(BAN_FILE); #else unlink(BAN_FILE); #endif } } // end save_bans
void SaveWadincludeFile(const char* const filename) { char* fname; FILE* file; int x; unsigned len = strlen(filename) + 5; fname = (char*)Alloc(len); safe_snprintf(fname, len, "%s.wic", filename); _unlink(fname); file = SafeOpenWrite(fname); WadInclude_i it; for (it = g_WadInclude.begin(); it != g_WadInclude.end(); it++) { x = it->size(); if (x) { SafeWrite(file, it->c_str(), x); SafeWrite(file, ";", 1); } } Free(fname); fclose(file); }
/////////////////////////////////////////////////////////////////////// // Function : osDeleteFile // Description : Delete a file // Return Value : - // Comments : void osDeleteFile(const char *n) { #ifdef _WINDOWS _unlink(n); #else unlink(n); #endif }
void removeFile(const char *filename) { bool isdir; isDir(filename,isdir); if (isdir) { #ifdef _WIN32 // no rmdir? if (RemoveDirectory(filename)==0) return; DWORD err = GetLastError(); if ( (err==ERROR_FILE_NOT_FOUND) || (err==ERROR_PATH_NOT_FOUND) ) return; throwError((int)err,"removeFile"); // shouldn't really pass win error here #else if (rmdir(filename) == 0) return; #endif } else { if (_unlink(filename) == 0) return; } if (ENOENT!=errno) throwError(errno,"removeFile"); }
main(int argc, char *argv[]) { char exe[128], uex[128]; int n; if (argc <= 1) return 1; n = strlen(argv[1]); if (n > 4 && !stricmp(argv[1]+n-4, ".exe")) { strcpy(exe, argv[1]); strcpy(uex, argv[1]); uex[n-4] = '\0'; strcat(uex, ".uex"); } else { strcpy(exe, argv[1]); strcat(exe, ".exe"); strcpy(uex, argv[1]); strcat(uex, ".uex"); } if (!_access(uex, 4)) { _unlink(exe); rename(uex, exe); } _execv(argv[1], argv+1); return 2; }
void FileList::DeleteFiles(const char *applicationDirectory) { char fullPath[512]; unsigned i,j; for (i=0; i < fileList.Size(); i++) { // The filename should not have .. in the path - if it does ignore it for (j=1; j < strlen(fileList[i].filename); j++) { if (fileList[i].filename[j]=='.' && fileList[i].filename[j-1]=='.') { #ifdef _DEBUG assert(0); #endif // Just cancel the deletion entirely return; } } strcpy(fullPath, applicationDirectory); strcat(fullPath, fileList[i].filename); _unlink(fullPath); } }
static int dfs_win32_unlink(struct dfs_filesystem *fs, const char *path) { int result; char *fp; fp = winpath_dirdup(WIN32_DIRDISK_ROOT, path); if (fp == RT_NULL) { rt_kprintf("out of memory.\n"); return -DFS_STATUS_ENOMEM; } result = GetFileAttributes(fp); if (result == INVALID_FILE_ATTRIBUTES) goto __err; if (result & FILE_ATTRIBUTE_DIRECTORY)//winnt.h { if (RemoveDirectory(fp) == RT_FALSE) goto __err; } else //(result & FILE_ATTRIBUTE_NORMAL) { if (_unlink(fp) < 0) goto __err; } rt_free(fp); return 0; __err: rt_free(fp); return win32_result_to_dfs(GetLastError()); }
// FsRenMovFile is called to transfer (copy or move) a file within the // plugin's file system. // int __stdcall FsRenMovFile(char *OldName, char *NewName, BOOL Move, BOOL OverWrite, RemoteInfoStruct *ri) { t_iPodError status = iPodApi.OpenSession(); CString BSDOldPath(OldName), BSDNewPath(NewName); t_MachError ret; BSDOldPath.Replace('\\', '/'); BSDNewPath.Replace('\\', '/'); if (!Move) { // Does a combination of AFCFileRefRead and AFCFileRefWrite, // a little silly as we lose the file attributes on the way. CString LocalCopy; iPodApi.GetTempFilename(LocalCopy); if (iPodApi.FileRead(BSDOldPath.GetBuffer(), LocalCopy.GetBuffer()) != FS_FILE_OK) return FS_FILE_READERROR; ret = iPodApi.FileWrite(BSDNewPath.GetBuffer(), LocalCopy.GetBuffer()); _unlink(LocalCopy); return ret; } bAborted = false; if (status == IPOD_ERR_OK) { if (!OverWrite) { if (iPodApi.FileExists(BSDNewPath.GetBuffer())) // Files exists, unfortunately we can't check the write permission // so asks the user's decision return FS_FILE_EXISTSRESUMEALLOWED; } ret = iPodApi.Move(BSDOldPath.GetBuffer(), BSDNewPath.GetBuffer()); return (ret == FS_FILE_OK) ? FS_FILE_OK : FS_FILE_READERROR; } return FS_FILE_READERROR; }
void CCopyThread::DoCopyFile(string source, string dest) { source = str_replaceallA(source,"\\\\","\\"); dest = str_replaceallA(dest,"\\\\","\\"); File_Size.QuadPart = File_Prog.QuadPart = 0; SetCurFile(source); if (Action == CDA_SDMODE) { //DebugMsg("Move %s to %s",source.c_str(),dest.c_str()); if (MoveFile(source.c_str(),dest.c_str())) Total_FilesCopied++; } else { //DebugMsg("Copy %s to %s",source.c_str(),dest.c_str()); if (CopyFileEx(source.c_str(),dest.c_str(),CopyProgressRoutine,(void*)this,NULL,0)) Total_FilesCopied++; } if (Action == CDA_MOVEFILES) { //DebugMsg("_unlink %s",source.c_str()); _unlink(source.c_str()); } // add file progress to total progress and reset file stuff Total_Prog.QuadPart += File_Prog.QuadPart; File_Prog.QuadPart = 0; File_Size.QuadPart = 0; }
// Given a directory remove the files located within it and then the directory itself void removeDirectory(std::string directory) { std::string CWD = getCurrentDirectory(); directory = CWD + DIR_SEPARATOR + directory; WIN32_FIND_DATA data; HANDLE h = FindFirstFile((directory + DIR_SEPARATOR + "*").c_str(), &data); if (h != NULL) { SetFileAttributes(directory.c_str(), FILE_ATTRIBUTE_NORMAL); FindNextFile(h, &data); // .. FindNextFile(h, &data); // . do { std::string filename = directory + DIR_SEPARATOR + data.cFileName; if (!SetFileAttributes(filename.c_str(), FILE_ATTRIBUTE_NORMAL)) { logEvent(ERROR,filename + ": " + ConvertLastErrorToString()); } int result = _unlink(filename.c_str()); if (result != 0) { logEvent(ERROR, filename + ": " + ConvertLastErrorToString()); } } while (FindNextFile(h,&data)); FindClose(h); } _rmdir(directory.c_str()); }
int Misc::file_Unlink(const char* path, int32_t maxAttempts ) { int32_t i; if( ! path || ! * path ) return -1; if( maxAttempts == 0 ) maxAttempts = 1; while( maxAttempts != 0 ) { if( _unlink( path ) != 0 ) return -1; i = 0; while( i < 100 ) { if( ! Misc::dir_Exists( path ) ) return 1; if( ++i > 50 ) // if it still doesn't show up, then we do some sleeping for the last 50ms _LUCENE_SLEEP( 1 ); } if( maxAttempts > 0 ) maxAttempts--; } return 0; }
/* * ============== * getfiledata * ============== */ long getfiledata(const char* const filename, char* buffer, const int buffersize) { long size = 0; int handle; time_t start, end; time(&start); if ((handle = _open(filename, O_RDONLY)) != -1) { int bytesread; Log("%-20s Restoring [%-13s - ", "BuildVisMatrix:", filename); while ((bytesread = _read(handle, buffer, min(32 * 1024, buffersize - size))) > 0) { size += bytesread; buffer += bytesread; } _close(handle); time(&end); Log("%10.3fMB] (%d)\n", size / (1024.0 * 1024.0), end - start); } if (buffersize != size) { Warning("Invalid file [%s] found. File will be rebuilt!\n", filename); _unlink(filename); } return size; }
bool Close(bool success=false) { void* mem; size_t size, offset_ctrl, offset_data; int bzerror; if(_bzpatch) BZ2_bzWriteClose(&bzerror, _bzpatch, 0, NULL, NULL); if(_stub) fclose(_stub); if(success) { // if(!ReadFile(_stubname.c_str(), mem, size)) return false; fseek(_patch, 0, SEEK_END); offset_data = ftell(_patch); fwrite(mem, 1, size, _patch); free(mem); // offset_ctrl = 16; fseek(_patch, 8, SEEK_SET); fwrite(&offset_ctrl, 1, 4, _patch); fwrite(&offset_data, 1, 4, _patch); if(_unlink(_stubname.c_str())!=0) return false; } if(_patch) fclose(_patch); _patch = NULL; _bzpatch = NULL; _stub = NULL; return true; }
FRESULT f_unlink ( const XCHAR *path /* Pointer to the file or directory path */ ) { FRESULT ret = FR_OK; const char* target= createFullPath(path); if (-1 == stat(target, &stats)) { return cvtERRNO(); } if (stats.st_mode & S_IFDIR) { if (_rmdir(target) == -1) { ret = FR_DENIED; } } else { // a concatenation of the mmc dir & the requested path if (_unlink(target) == -1) { ret = cvtERRNO(); } } return ret; }
/* <ed99c> ../engine/sv_steam3.cpp:827 */ void CSteam3Client::InitClient() { if (m_bLoggedOn) return; m_bLoggedOn = true; _unlink("steam_appid.txt"); if (!getenv("SteamAppId")) { int nAppID = GetGameAppID(); if (nAppID > 0) { FILE* f = fopen("steam_appid.txt", "w+"); if (f) { fprintf(f, "%d\n", nAppID); fclose(f); } } } if (!SteamAPI_Init()) Sys_Error("Failed to initalize authentication interface. Exiting...\n"); m_bLogOnResult = false; }
void Fatal () // fatal error, attempt to shut down and exit // if we already tried to shut down -- just abort without doing anything { static BOOL fTwice; if (!fTwice) { fTwice = TRUE; if (pnmBsc) pnmBsc->close(); if (pdbBsc) { pdbBsc->Close(); // do not commit! // see if we should delete if (fDeleteOnFatal && OutputFileName) { _unlink(OutputFileName); } else // restore the file time if possible... if (OutputFileName && sbufBsc.st_atime && sbufBsc.st_mtime) { struct _utimbuf ubuf; ubuf.actime = sbufBsc.st_atime; ubuf.modtime = sbufBsc.st_mtime; _utime(OutputFileName, &ubuf); } } } exit(4); }
bool genlib(compile_t* c, ast_t* program) { if(!reachable_actors(c, program) || !generate_actors(c, program) || !genheader(c) ) return false; const char* file_o = genobj(c); if(file_o == NULL) return false; if(c->opt->limit < PASS_ALL) return true; if(!link_lib(c, file_o)) return false; #ifdef PLATFORM_IS_WINDOWS _unlink(file_o); #else unlink(file_o); #endif return true; }
bool Delete(bool returnFalseOnRegistryRemovalFailure=false) { if(!*filename) return true; // guess it already didn't exist // remove read-only attribute so Windows will let us delete it // (our temporary files are read-only to discourage other apps from tampering) DWORD attributes = GetFileAttributes(filename); if(attributes & FILE_ATTRIBUTE_READONLY) SetFileAttributes(filename, attributes & ~FILE_ATTRIBUTE_READONLY); if(_unlink(filename) == 0 || errno != EACCES) { // remove it from our registry of files that need to be deleted, to reduce accumulation bool removed = TempFiles::RemoveEntryFromGarbageRegistry(filename); *filename = '\0'; return removed || !returnFalseOnRegistryRemovalFailure; // successfully deleted or already didn't exist, return true unless registry removal failure notification was requested and that failed } // restore read-only if we couldn't delete it (not sure if this ever succeeds or matters though) if(attributes & FILE_ATTRIBUTE_READONLY) SetFileAttributes(filename, attributes); return false; // failed to delete read-only or in-use file }
unsigned int CRhoFile::deleteFile( const char* szFilePath ){ #if defined(WINDOWS_PLATFORM) return (unsigned int)_unlink(szFilePath); #else return (unsigned int)remove(szFilePath); #endif }