Skip to content

Commit

Permalink
Limit probing I/O to 16 KB for local files also.
Browse files Browse the repository at this point in the history
  • Loading branch information
jlindgren90 committed Apr 29, 2013
1 parent 89e1806 commit c6d076a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
47 changes: 27 additions & 20 deletions src/audacious/probe-buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ static int64_t probe_buffer_fread (void * buffer, int64_t size, int64_t count,
static int64_t probe_buffer_fwrite (const void * data, int64_t size, int64_t count,
VFSFile * file)
{
/* not implemented */
return 0;
return 0; /* not allowed */
}

static int probe_buffer_getc (VFSFile * file)
Expand All @@ -84,7 +83,7 @@ static int probe_buffer_fseek (VFSFile * file, int64_t offset, int whence)
ProbeBuffer * p = vfs_get_handle (file);

if (whence == SEEK_END)
return -1;
return -1; /* not allowed */

if (whence == SEEK_CUR)
offset += p->at;
Expand Down Expand Up @@ -117,18 +116,26 @@ static int64_t probe_buffer_ftell (VFSFile * file)
static bool_t probe_buffer_feof (VFSFile * file)
{
ProbeBuffer * p = vfs_get_handle (file);
return (p->at < p->filled) ? FALSE : vfs_feof (p->file);

if (p->at < p->filled)
return FALSE;
if (p->at == sizeof p->buffer)
return TRUE;

return vfs_feof (p->file);
}

static int probe_buffer_ftruncate (VFSFile * file, int64_t size)
{
/* not implemented */
return -1;
return -1; /* not allowed */
}

static int64_t probe_buffer_fsize (VFSFile * file)
{
return vfs_fsize (((ProbeBuffer *) vfs_get_handle (file))->file);
ProbeBuffer * p = vfs_get_handle (file);

int64_t size = vfs_fsize (p->file);
return MIN (size, sizeof p->buffer);
}

static char * probe_buffer_get_metadata (VFSFile * file, const char * field)
Expand All @@ -138,19 +145,19 @@ static char * probe_buffer_get_metadata (VFSFile * file, const char * field)

static VFSConstructor probe_buffer_table =
{
.vfs_fopen_impl = NULL,
.vfs_fclose_impl = probe_buffer_fclose,
.vfs_fread_impl = probe_buffer_fread,
.vfs_fwrite_impl = probe_buffer_fwrite,
.vfs_getc_impl = probe_buffer_getc,
.vfs_ungetc_impl = probe_buffer_ungetc,
.vfs_fseek_impl = probe_buffer_fseek,
.vfs_rewind_impl = probe_buffer_rewind,
.vfs_ftell_impl = probe_buffer_ftell,
.vfs_feof_impl = probe_buffer_feof,
.vfs_ftruncate_impl = probe_buffer_ftruncate,
.vfs_fsize_impl = probe_buffer_fsize,
.vfs_get_metadata_impl = probe_buffer_get_metadata,
.vfs_fopen_impl = NULL,
.vfs_fclose_impl = probe_buffer_fclose,
.vfs_fread_impl = probe_buffer_fread,
.vfs_fwrite_impl = probe_buffer_fwrite,
.vfs_getc_impl = probe_buffer_getc,
.vfs_ungetc_impl = probe_buffer_ungetc,
.vfs_fseek_impl = probe_buffer_fseek,
.vfs_rewind_impl = probe_buffer_rewind,
.vfs_ftell_impl = probe_buffer_ftell,
.vfs_feof_impl = probe_buffer_feof,
.vfs_ftruncate_impl = probe_buffer_ftruncate,
.vfs_fsize_impl = probe_buffer_fsize,
.vfs_get_metadata_impl = probe_buffer_get_metadata,
};

VFSFile * probe_buffer_new (const char * filename)
Expand Down
5 changes: 1 addition & 4 deletions src/audacious/probe.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ static bool_t check_opened (ProbeState * state)
return FALSE;

AUDDBG ("Opening %s.\n", state->filename);
if (vfs_is_remote (state->filename))
state->handle = probe_buffer_new (state->filename);
else
state->handle = vfs_fopen (state->filename, "r");
state->handle = probe_buffer_new (state->filename);

if (state->handle != NULL)
return TRUE;
Expand Down

0 comments on commit c6d076a

Please sign in to comment.