Add support for resource fork files in the .AppleDouble/ directory.

This commit is contained in:
Erik de Castro Lopo 2005-03-09 10:29:32 +00:00
parent bc1e9e66f7
commit 611e60260d
4 changed files with 45 additions and 27 deletions

View File

@ -1,3 +1,16 @@
2005-03-09 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
* src/common.h
Add a directory field for storing the file directory to the SF_PRIVATE
struct.
* src/sndfile.c
Grab the directory name when copying the file path.
* src/file_io.c
Cleanup psf_open_rsrc() and also check for resource fork in
.AppleDouble/filename.
2005-03-01 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
* src/svx.c

View File

@ -184,6 +184,7 @@ typedef struct sf_private_tag
char filepath [SF_FILENAME_LEN] ;
char rsrcpath [SF_FILENAME_LEN] ;
char directory [SF_FILENAME_LEN] ;
char filename [SF_FILENAME_LEN / 4] ;
char syserr [SF_SYSERR_LEN] ;

View File

@ -94,14 +94,12 @@ psf_fclose (SF_PRIVATE *psf)
int
psf_open_rsrc (SF_PRIVATE *psf, int open_mode)
{ char *fname ;
{
if (psf->rsrcdes > 0)
return 0 ;
/* Test for MacOSX style resource fork on HPFS or HPFS+ filesystems. */
LSF_SNPRINTF (psf->rsrcpath, sizeof (psf->rsrcpath), "%s/rsrc", psf->filepath) ;
psf->error = SFE_NO_ERROR ;
if ((psf->rsrcdes = psf_open_fd (psf->rsrcpath, open_mode)) >= 0)
{ psf->rsrclength = psf_get_filelen_fd (psf->rsrcdes) ;
@ -114,28 +112,28 @@ psf_open_rsrc (SF_PRIVATE *psf, int open_mode)
} ;
/*
** Now try for a resource fork stored as a separate file.
** Grab the un-adulterated filename again.
** Now try for a resource fork stored as a separate file in the same
** directory, but preceded with a dot underscore.
*/
LSF_SNPRINTF (psf->rsrcpath, sizeof (psf->rsrcpath), "%s", psf->filepath) ;
if ((fname = strrchr (psf->rsrcpath, '/')) != NULL)
fname ++ ;
else if ((fname = strrchr (psf->rsrcpath, '\\')) != NULL)
fname ++ ;
else
fname = psf->rsrcpath ;
memmove (fname + 2, fname, strlen (fname) + 1) ;
fname [0] = '.' ;
fname [1] = '_' ;
LSF_SNPRINTF (psf->rsrcpath, sizeof (psf->rsrcpath), "%s._%s", psf->directory, psf->filename) ;
psf->error = SFE_NO_ERROR ;
if ((psf->rsrcdes = psf_open_fd (psf->rsrcpath, open_mode)) >= 0)
{ psf->rsrclength = psf_get_filelen_fd (psf->rsrcdes) ;
return SFE_NO_ERROR ;
} ;
/*
** Now try for a resource fork stored in a separate file in the
** .AppleDouble/ directory.
*/
LSF_SNPRINTF (psf->rsrcpath, sizeof (psf->rsrcpath), "%s.AppleDouble/%s", psf->directory, psf->filename) ;
psf->error = SFE_NO_ERROR ;
if ((psf->rsrcdes = psf_open_fd (psf->rsrcpath, open_mode)) >= 0)
{ psf->rsrclength = psf_get_filelen_fd (psf->rsrcdes) ;
return SFE_NO_ERROR ;
} ;
/* No resource file found. */
if (psf->rsrcdes == -1)
psf_log_syserr (psf, errno) ;
@ -290,7 +288,7 @@ psf_fread (void *ptr, sf_count_t bytes, sf_count_t items, SF_PRIVATE *psf)
return 0 ;
while (items > 0)
{ /* Break the writes down to a sensible size. */
{ /* Break the read down to a sensible size. */
count = (items > SENSIBLE_SIZE) ? SENSIBLE_SIZE : (ssize_t) items ;
count = read (psf->filedes, ((char*) ptr) + total, (size_t) count) ;

View File

@ -2168,19 +2168,25 @@ save_header_info (SF_PRIVATE *psf)
static void
copy_filename (SF_PRIVATE *psf, const char *path)
{ const char *cptr ;
{ const char *ccptr ;
char *cptr ;
LSF_SNPRINTF (psf->filepath, sizeof (psf->filepath), "%s", path) ;
if ((cptr = strrchr (path, '/')) || (cptr = strrchr (path, '\\')))
cptr ++ ;
if ((ccptr = strrchr (path, '/')) || (ccptr = strrchr (path, '\\')))
ccptr ++ ;
else
cptr = path ;
ccptr = path ;
memset (psf->filename, 0, sizeof (psf->filename)) ;
LSF_SNPRINTF (psf->filename, sizeof (psf->filename), "%s", ccptr) ;
LSF_SNPRINTF (psf->filename, sizeof (psf->filename), "%s", cptr) ;
/* Now grab the directory. */
LSF_SNPRINTF (psf->directory, sizeof (psf->directory), "%s", path) ;
if ((cptr = strrchr (psf->directory, '/')) || (cptr = strrchr (psf->directory, '\\')))
cptr [1] = 0 ;
else
psf->directory [0] = 0 ;
return ;
} /* copy_filename */
/*==============================================================================
@ -2188,7 +2194,7 @@ copy_filename (SF_PRIVATE *psf, const char *path)
static int
psf_close (SF_PRIVATE *psf)
{ int error ;
{ int error ;
if (psf->close)
error = psf->close (psf) ;