diff options
author | ivo <ivo@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2004-09-08 01:11:16 +0000 |
---|---|---|
committer | ivo <ivo@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2004-09-08 01:11:16 +0000 |
commit | b8c10b5b267acc651c49243ce75c2c22f3a13260 (patch) | |
tree | ba638fc74f92815f95d5c1fc8901e8e068394159 /libvo | |
parent | 28aac68c03718b4956d8a4fe5b0eced6e9561340 (diff) |
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 :-)
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@13284 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'libvo')
-rw-r--r-- | libvo/vo_jpeg.c | 104 |
1 files changed, 43 insertions, 61 deletions
diff --git a/libvo/vo_jpeg.c b/libvo/vo_jpeg.c index aa3b328a27..e2843bb508 100644 --- a/libvo/vo_jpeg.c +++ b/libvo/vo_jpeg.c @@ -80,18 +80,23 @@ static int framenum = 0; /* ------------------------------------------------------------------------- */ -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 @@ static uint32_t config(uint32_t width, uint32_t height, uint32_t d_width, 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 @@ static uint32_t draw_frame(uint8_t *src[]) 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++; |