Skip to content

Commit fa8e817

Browse files
committed
Regularize the various VFS seek implementations
1 parent a0075bd commit fa8e817

4 files changed

Lines changed: 10 additions & 33 deletions

File tree

libretro-common/include/libretro.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2834,8 +2834,7 @@ typedef int64_t (RETRO_CALLCONV *retro_vfs_tell_t)(struct retro_vfs_file_handle
28342834
* @param stream The file to set the position of.
28352835
* @param offset The new position, in bytes.
28362836
* @param seek_position The position to seek from.
2837-
* @return The new position,
2838-
* or -1 if there was an error.
2837+
* @return 0 on success, -1 on failure.
28392838
* @since VFS API v1
28402839
* @see File Seek Positions
28412840
* @see filestream_seek

libretro-common/vfs/vfs_implementation.c

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,6 @@ int64_t retro_vfs_file_seek_internal(
233233
libretro_vfs_implementation_file *stream,
234234
int64_t offset, int whence)
235235
{
236-
int64_t val;
237-
238236
if (!stream)
239237
return -1;
240238

@@ -254,7 +252,7 @@ int64_t retro_vfs_file_seek_internal(
254252
#elif defined(HAVE_64BIT_OFFSETS)
255253
return fseeko(stream->fp, (off_t)offset, whence);
256254
#else
257-
return fseek(stream->fp, (long)offset, whence);
255+
return fseek(stream->fp, (long)offset, whence) != 0 ? -1 : 0;
258256
#endif
259257
}
260258
#ifdef HAVE_MMAP
@@ -298,10 +296,7 @@ int64_t retro_vfs_file_seek_internal(
298296
}
299297
#endif
300298

301-
if ((val = lseek(stream->fd, (off_t)offset, whence)) < 0)
302-
return -1;
303-
304-
return val;
299+
return lseek(stream->fd, (off_t)offset, whence) == -1 ? -1 : 0;
305300
}
306301

307302
/**
@@ -750,8 +745,6 @@ int64_t retro_vfs_file_truncate_impl(libretro_vfs_implementation_file *stream, i
750745

751746
int64_t retro_vfs_file_tell_impl(libretro_vfs_implementation_file *stream)
752747
{
753-
int64_t val;
754-
755748
if (!stream)
756749
return -1;
757750

@@ -781,10 +774,7 @@ int64_t retro_vfs_file_tell_impl(libretro_vfs_implementation_file *stream)
781774
RETRO_VFS_FILE_ACCESS_HINT_FREQUENT_ACCESS)
782775
return stream->mappos;
783776
#endif
784-
if ((val = lseek(stream->fd, 0, SEEK_CUR)) < 0)
785-
return -1;
786-
787-
return val;
777+
return lseek(stream->fd, 0, SEEK_CUR);
788778
}
789779

790780
int64_t retro_vfs_file_seek_impl(libretro_vfs_implementation_file *stream,

libretro-common/vfs/vfs_implementation_smb.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ static bool smb_build_path(char *dest, size_t dest_size, const char *relative_pa
249249
settings_t *settings = config_get_ptr();
250250
char temp_path[PATH_MAX_LENGTH];
251251
const char *p;
252-
252+
253253
if (!settings)
254254
{
255255
RARCH_ERR("[SMB] Cannot retrieve settings\n");
@@ -415,10 +415,8 @@ int64_t retro_vfs_file_write_smb(libretro_vfs_implementation_file *stream,
415415
int64_t retro_vfs_file_seek_smb(libretro_vfs_implementation_file *stream,
416416
int64_t offset, int whence)
417417
{
418-
uint64_t newpos = 0;
419418
struct smb2fh *fh;
420419
struct smb2_context *ctx;
421-
int64_t ret;
422420

423421
if (!smb_initialized || !stream || !stream->smb_ctx)
424422
return -1;
@@ -440,15 +438,13 @@ int64_t retro_vfs_file_seek_smb(libretro_vfs_implementation_file *stream,
440438
if (whence != SEEK_SET && whence != SEEK_CUR && whence != SEEK_END)
441439
return -1;
442440

443-
/* libsmb2 returns status via ret, and the new offset via out param */
444-
ret = smb2_lseek(ctx, fh, offset, whence, &newpos);
445-
if (ret < 0)
441+
if (smb2_lseek(ctx, fh, offset, whence, NULL) == -EINVAL)
446442
{
447443
RARCH_ERR("[SMB] Seek error: %s\n", smb2_get_error(ctx));
448444
return -1;
449445
}
450446

451-
return (int64_t)newpos;
447+
return 0;
452448
}
453449

454450
/* return the current byte offset in an open file */
@@ -457,7 +453,6 @@ int64_t retro_vfs_file_tell_smb(libretro_vfs_implementation_file *stream)
457453
uint64_t cur = 0;
458454
struct smb2fh *fh;
459455
struct smb2_context *ctx;
460-
int64_t ret;
461456

462457
if (!smb_initialized || !stream || !stream->smb_ctx)
463458
return -1;
@@ -473,8 +468,7 @@ int64_t retro_vfs_file_tell_smb(libretro_vfs_implementation_file *stream)
473468
if (!ctx)
474469
return -1;
475470

476-
ret = smb2_lseek(ctx, fh, 0, SEEK_CUR, &cur);
477-
if (ret < 0)
471+
if (smb2_lseek(ctx, fh, 0, SEEK_CUR, &cur) == -EINVAL)
478472
{
479473
RARCH_ERR("[SMB] Tell error: %s\n", smb2_get_error(ctx));
480474
return -1;

libretro-common/vfs/vfs_implementation_uwp.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,7 @@ int64_t retro_vfs_file_tell_impl(libretro_vfs_implementation_file* stream)
138138
#endif
139139
return _ftelli64(stream->fp);
140140
}
141-
if (lseek(stream->fd, 0, SEEK_CUR) < 0)
142-
return -1;
143-
144-
return 0;
141+
return lseek(stream->fd, 0, SEEK_CUR);
145142
}
146143

147144
int64_t retro_vfs_file_seek_internal(
@@ -159,10 +156,7 @@ int64_t retro_vfs_file_seek_internal(
159156
#endif
160157
return _fseeki64(stream->fp, offset, whence);
161158
}
162-
if (lseek(stream->fd, (off_t)offset, whence) < 0)
163-
return -1;
164-
165-
return 0;
159+
return lseek(stream->fd, (off_t)offset, whence) == -1 ? -1 : 0;
166160
}
167161

168162
int64_t retro_vfs_file_seek_impl(libretro_vfs_implementation_file* stream,

0 commit comments

Comments
 (0)