/* * Closes srcHandle if it's not -1. * Closes dstHandle if it's not -1. * Removes unlinkpath from the unlinkHandle dir if it's not NULL. * Frees 'buf' if not NULL. * Always returns -1. * errno is what was before the call. */ static int copyError(uio_Handle *srcHandle, uio_Handle *dstHandle, uio_DirHandle *unlinkHandle, const char *unlinkPath, uint8 *buf) { int savedErrno; savedErrno = errno; log_add (log_Debug, "Error while copying: %s", strerror (errno)); if (srcHandle != NULL) uio_close (srcHandle); if (dstHandle != NULL) uio_close (dstHandle); if (unlinkPath != NULL) uio_unlink (unlinkHandle, unlinkPath); if (buf != NULL) HFree(buf); errno = savedErrno; return -1; }
void uio_releaseStdioAccess(uio_StdioAccessHandle *handle) { if (handle->tempDir != NULL) { if (uio_unlink(handle->tempDir, handle->fileName) == -1) { #ifdef DEBUG fprintf(stderr, "Error: Could not remove temporary file: " "%s\n", strerror(errno)); #endif } // Need to free this handle in advance. There should be no handles // to a dir left when removing it. uio_DirHandle_unref(handle->tempDir); handle->tempDir = NULL; if (uio_rmdir(handle->tempRoot, handle->tempDirName) == -1) { #ifdef DEBUG fprintf(stderr, "Error: Could not remove temporary directory: " "%s\n", strerror(errno)); #endif } } uio_StdioAccessHandle_delete(handle); }
/* * Closes srcHandle if it's not -1. * Closes dstHandle if it's not -1. * Removes unlinkpath from the unlinkHandle dir if it's not NULL. * Frees 'buf' if not NULL. * Always returns -1. * errno is what was before the call. */ static int uio_copyError(uio_Handle *srcHandle, uio_Handle *dstHandle, uio_DirHandle *unlinkHandle, const char *unlinkPath, uio_uint8 *buf) { int savedErrno; savedErrno = errno; #ifdef DEBUG fprintf(stderr, "Error while copying: %s\n", strerror(errno)); #endif if (srcHandle != NULL) uio_close(srcHandle); if (dstHandle != NULL) uio_close(dstHandle); if (unlinkPath != NULL) uio_unlink(unlinkHandle, unlinkPath); if (buf != NULL) uio_free(buf); errno = savedErrno; return -1; }
BOOLEAN DoSaveTeam (MELEE_STATE *pMS) { STAMP MsgStamp; char file[NAME_MAX]; uio_Stream *stream; CONTEXT OldContext; bool saveOk = false; snprintf (file, sizeof file, "%s.mle", MeleeSetup_getTeamName (pMS->meleeSetup, pMS->side)); LockMutex (GraphicsLock); OldContext = SetContext (ScreenContext); ConfirmSaveLoad (&MsgStamp); // Show the "Saving . . ." message. UnlockMutex (GraphicsLock); stream = uio_fopen (meleeDir, file, "wb"); if (stream != NULL) { saveOk = (MeleeTeam_serialize (&pMS->meleeSetup->teams[pMS->side], stream) == 0); uio_fclose (stream); if (!saveOk) uio_unlink (meleeDir, file); } pMS->load.top = 0; pMS->load.cur = 0; // Undo the screen damage done by the "Saving . . ." message. LockMutex (GraphicsLock); DrawStamp (&MsgStamp); DestroyDrawable (ReleaseDrawable (MsgStamp.frame)); SetContext (OldContext); UnlockMutex (GraphicsLock); if (!saveOk) SaveProblem (); // Update the team list; a previously existing team may have been // deleted when save failed. LoadTeamList (pMS); SelectTeamByFileName (pMS, file); return (stream != 0); }
static int debugCmdRm(DebugContext *debugContext, int argc, char *argv[]) { int retVal; if (argc != 2) { fprintf(debugContext->err, "Invalid number of arguments.\n"); return 1; } retVal = uio_unlink(debugContext->cwd, argv[1]); if (retVal == -1) { fprintf(debugContext->err, "Could not remove file: %s\n", strerror(errno)); return 1; } return 0; }
BOOLEAN DeleteResFile (uio_DirHandle *dir, const char *filename) { return (uio_unlink (dir, filename) == 0); }