Mercurial > mplayer.hg
changeset 13283:858b7e04718c
This patch moves the directory creation code to a separate function. I have
tried to re-use as much code as possible, to reduce the size of the patch.
All duplicate code is removed, resulting in my first patch that actually
decreases the size of the binary by about 700 bytes :-)
author | ivo |
---|---|
date | Wed, 08 Sep 2004 01:11:16 +0000 |
parents | a46dce85af0a |
children | 6370626e902b |
files | libvo/vo_jpeg.c |
diffstat | 1 files changed, 43 insertions(+), 61 deletions(-) [+] |
line wrap: on
line diff
--- a/libvo/vo_jpeg.c Tue Sep 07 20:27:05 2004 +0000 +++ b/libvo/vo_jpeg.c Wed Sep 08 01:11:16 2004 +0000 @@ -80,18 +80,23 @@ /* ------------------------------------------------------------------------- */ -static uint32_t config(uint32_t width, uint32_t height, uint32_t d_width, - uint32_t d_height, uint32_t fullscreen, char *title, - uint32_t format) -{ - char buf[BUFLENGTH]; +/** \brief Create a directory. + * + * This function creates a directory. If it already exists, it tests if + * it's a directory and not something else, and if it is, it tests whether + * the directory is writable or not. + * + * \param buf Pointer to directory name. + * \param verbose Verbose on success. If verbose is non-zero, it will print + * a message if it was successful in creating the directory. + * + * \return nothing In case anything fails, the player will exit. If it + * returns, everything went well. + */ + +void jpeg_mkdir(char *buf, int verbose) { struct stat stat_p; - /* Create outdir. - * If it already exists, test if it's a writable directory */ - - snprintf(buf, BUFLENGTH, "%s", jpeg_outdir); - if ( mkdir(buf, 0755) < 0 ) { switch (errno) { /* use switch in case other errors need to be caught and handled in the future */ @@ -109,26 +114,42 @@ exit_player(MSGTR_Exit_error); } if ( !(stat_p.st_mode & S_IWUSR) ) { - mp_msg(MSGT_VO, MSGL_ERR, "%s: %s\n", info.short_name, - MSGTR_VO_JPEG_DirExistsButNotWritable); + mp_msg(MSGT_VO, MSGL_ERR, "%s: %s - %s\n", info.short_name, + buf, MSGTR_VO_JPEG_DirExistsButNotWritable); exit_player(MSGTR_Exit_error); } - mp_msg(MSGT_VO, MSGL_INFO, "%s: %s\n", info.short_name, - MSGTR_VO_JPEG_DirExistsAndIsWritable); + mp_msg(MSGT_VO, MSGL_INFO, "%s: %s - %s\n", info.short_name, + buf, MSGTR_VO_JPEG_DirExistsAndIsWritable); break; default: mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n", info.short_name, MSGTR_VO_JPEG_GenericError, strerror(errno) ); - mp_msg(MSGT_VO, MSGL_ERR, "%s: %s\n", info.short_name, - MSGTR_VO_JPEG_CantCreateDirectory); + mp_msg(MSGT_VO, MSGL_ERR, "%s: %s - %s\n", info.short_name, + buf, MSGTR_VO_JPEG_CantCreateDirectory); exit_player(MSGTR_Exit_error); } /* end switch */ - } else { - mp_msg(MSGT_VO, MSGL_INFO, "%s: %s\n", info.short_name, - MSGTR_VO_JPEG_DirectoryCreateSuccess); + } else if ( verbose ) { + mp_msg(MSGT_VO, MSGL_INFO, "%s: %s - %s\n", info.short_name, + buf, MSGTR_VO_JPEG_DirectoryCreateSuccess); } /* end if */ +} + +/* ------------------------------------------------------------------------- */ + +static uint32_t config(uint32_t width, uint32_t height, uint32_t d_width, + uint32_t d_height, uint32_t fullscreen, char *title, + uint32_t format) +{ + char buf[BUFLENGTH]; + + /* Create outdir. */ + + snprintf(buf, BUFLENGTH, "%s", jpeg_outdir); + + jpeg_mkdir(buf, 1); /* This function only returns if creation was + successful. If not, the player will exit. */ image_height = height; image_width = width; @@ -210,48 +231,9 @@ snprintf(subdirname, BUFLENGTH, "%s%08d", jpeg_subdirs, ++subdircounter); snprintf(buf, BUFLENGTH, "%s/%s", jpeg_outdir, subdirname); - if ( mkdir(buf, 0755) < 0 ) { - switch (errno) { /* use switch in case other errors need to be - caught and handled in the future */ - case EEXIST: - if ( stat(buf, &stat_p) < 0 ) { - mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n", - info.short_name, MSGTR_VO_JPEG_GenericError, - strerror(errno) ); - mp_msg(MSGT_VO, MSGL_ERR, "%s: %s %s\n", - info.short_name, MSGTR_VO_JPEG_UnableToAccess, - buf); - exit_player(MSGTR_Exit_error); - } - if ( !S_ISDIR(stat_p.st_mode) ) { - mp_msg(MSGT_VO, MSGL_ERR, "\n%s: %s %s\n", - info.short_name, buf, - MSGTR_VO_JPEG_ExistsButNoDirectory); - exit_player(MSGTR_Exit_error); - } - if ( !(stat_p.st_mode & S_IWUSR) ) { - mp_msg(MSGT_VO, MSGL_ERR, "\n%s: %s - %s\n", - info.short_name, buf, - MSGTR_VO_JPEG_DirExistsButNotWritable); - exit_player(MSGTR_Exit_error); - } - - mp_msg(MSGT_VO, MSGL_INFO, "\n%s: %s - %s\n", - info.short_name, buf, - MSGTR_VO_JPEG_DirExistsAndIsWritable); - break; - - default: - mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n", info.short_name, - MSGTR_VO_JPEG_GenericError, strerror(errno) ); - mp_msg(MSGT_VO, MSGL_ERR, "\n%s: %s - %s.\n", - info.short_name, buf, - MSGTR_VO_JPEG_CantCreateDirectory); - exit_player(MSGTR_Exit_error); - break; - } - } /* switch */ - } /* if !framecounter && jpeg_subdirs */ + jpeg_mkdir(buf, 0); /* This function only returns if creation was + successful. If not, the player will exit. */ + } framenum++;