Make sf_set_string() return an error if trying to set a string when in read mode.

This commit is contained in:
Erik de Castro Lopo 2004-08-31 12:06:33 +00:00
parent 2e9e61e19d
commit ca2b7af0f6
3 changed files with 14 additions and 3 deletions

View File

@ -315,15 +315,16 @@ enum
SFE_BAD_OPEN_MODE,
SFE_OPEN_PIPE_RDWR,
SFE_RDWR_POSITION,
SFE_RDWR_BAD_HEADER,
SFE_STR_NO_SUPPORT,
SFE_STR_NOT_WRITE,
SFE_STR_MAX_DATA,
SFE_STR_MAX_COUNT,
SFE_STR_BAD_TYPE,
SFE_STR_NO_ADD_END,
SFE_STR_BAD_STRING,
SFE_STR_WEIRD,
SFE_RDWR_BAD_HEADER,
SFE_WAV_NO_RIFF,
SFE_WAV_NO_WAVE,
@ -492,6 +493,7 @@ int psf_calc_max_all_channels (SF_PRIVATE *psf, double *peaks, int normalize) ;
/* Functions in strings.c. */
const char* psf_get_string (SF_PRIVATE *psf, int str_type) ;
int psf_set_string (SF_PRIVATE *psf, int str_type, const char *str) ;
int psf_store_string (SF_PRIVATE *psf, int str_type, const char *str) ;
/* Default seek function. Use for PCM and float encoded data. */

View File

@ -86,15 +86,16 @@ ErrorStruct SndfileErrors [] =
{ SFE_BAD_OPEN_MODE , "Error: bad mode parameter for file open." },
{ SFE_OPEN_PIPE_RDWR , "Error: attempt toopen a pipe in read/write mode." },
{ SFE_RDWR_POSITION , "Error on RDWR position (cryptic)." },
{ SFE_RDWR_BAD_HEADER , "Error : Cannot open file in read/write mode due to string data in header." },
{ SFE_STR_NO_SUPPORT , "Error : File type does not support string data." },
{ SFE_STR_NOT_WRITE , "Error : Trying to set a string when file is not in write mode." },
{ SFE_STR_MAX_DATA , "Error : Maximum string data storage reached." },
{ SFE_STR_MAX_COUNT , "Error : Maximum string data count reached." },
{ SFE_STR_BAD_TYPE , "Error : Bad string data type." },
{ SFE_STR_NO_ADD_END , "Error : file type does not support strings added at end of file." },
{ SFE_STR_BAD_STRING , "Error : bad string." },
{ SFE_STR_WEIRD , "Error : Weird string error." },
{ SFE_RDWR_BAD_HEADER , "Error : Cannot open file in read/write mode due to string data in header." },
{ SFE_WAV_NO_RIFF , "Error in WAV file. No 'RIFF' chunk marker." },
{ SFE_WAV_NO_WAVE , "Error in WAV file. No 'WAVE' chunk marker." },
@ -1061,7 +1062,7 @@ sf_set_string (SNDFILE *sndfile, int str_type, const char* str)
VALIDATE_SNDFILE_AND_ASSIGN_PSF (sndfile, psf, 1) ;
return psf_store_string (psf, str_type, str) ;
return psf_set_string (psf, str_type, str) ;
} /* sf_get_string */
/*==============================================================================

View File

@ -151,6 +151,14 @@ psf_store_string (SF_PRIVATE *psf, int str_type, const char *str)
return 0 ;
} /* psf_store_string */
int
psf_set_string (SF_PRIVATE *psf, int str_type, const char *str)
{ if (psf->mode == SFM_READ)
return SFE_STR_NOT_WRITE ;
return psf_store_string (psf, str_type, str) ;
} /* psf_set_string */
const char*
psf_get_string (SF_PRIVATE *psf, int str_type)
{ int k ;