Pete Batard's patches offset types especially for MinGW and MS Visual C.

This commit is contained in:
R. Bernstein
2012-03-03 12:10:53 -05:00
parent f269abeb07
commit 739928df7b
18 changed files with 151 additions and 79 deletions

View File

@@ -31,7 +31,7 @@
/* portable.h has to come first else _FILE_OFFSET_BITS are redefined in
say opensolaris. */
#include "portable.h"
#include "filemode.h"
#include <cdio/cdio.h>
#include <cdio/iso9660.h>

View File

@@ -37,7 +37,7 @@
/* portable.h has to come first else _FILE_OFFSET_BITS are redefined in
say opensolaris. */
#include "portable.h"
#include "filemode.h"
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>

View File

@@ -28,7 +28,7 @@
/* portable.h has to come first else _FILE_OFFSET_BITS are redefined in
say opensolaris. */
#include "portable.h"
#include "filemode.h"
#ifdef HAVE_STDIO_H
#include <stdio.h>

View File

@@ -51,7 +51,7 @@ typedef struct udf_dirent_s {
/* This field has to come last because it is variable in length. */
udf_file_entry_t fe;
} udf_dirent_t;;
} udf_dirent_t;

View File

@@ -27,8 +27,7 @@
#include <time.h>
#ifndef HAVE_STRUCT_TIMESPEC
#define HAVE_STRUCT_TIMESPEC
#if defined(__MINGW32__) && !defined(__MINGW64__)
struct timespec {
time_t tv_sec; /* Seconds */
long tv_nsec; /* Nanoseconds */

View File

@@ -1,5 +1,6 @@
/*
Copyright (C) 2004, 2005, 2006, 2008, 2010 Rocky Bernstein <rocky@gnu.org>
Copyright (C) 2004, 2005, 2006, 2008, 2010, 2012
Rocky Bernstein <rocky@gnu.org>
Copyright (C) 2000 Herbert Valerio Riedel <hvr@gnu.org>
This program is free software: you can redistribute it and/or modify
@@ -28,6 +29,18 @@
#include <stdlib.h>
#include <cdio/types.h>
#if !defined CDIO_INLINE
#if defined(__cplusplus) || defined(inline)
#define CDIO_INLINE inline
#elif defined(__GNUC__)
#define CDIO_INLINE __inline__
#elif defined(_MSC_VER)
#define CDIO_INLINE __inline
#else
#define CDIO_INLINE
#endif
#endif /* CDIO_INLINE */
#undef MAX
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
@@ -40,7 +53,7 @@
#undef CLAMP
#define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
static inline uint32_t
static CDIO_INLINE uint32_t
_cdio_len2blocks (uint32_t i_len, uint16_t i_blocksize)
{
uint32_t i_blocks;
@@ -53,13 +66,13 @@ _cdio_len2blocks (uint32_t i_len, uint16_t i_blocksize)
}
/* round up to next block boundary */
static inline unsigned
static CDIO_INLINE unsigned
_cdio_ceil2block (unsigned offset, uint16_t i_blocksize)
{
return _cdio_len2blocks (offset, i_blocksize) * i_blocksize;
}
static inline unsigned int
static CDIO_INLINE unsigned int
_cdio_ofs_add (unsigned offset, unsigned length, uint16_t i_blocksize)
{
if (i_blocksize - (offset % i_blocksize) < length)
@@ -70,7 +83,7 @@ _cdio_ofs_add (unsigned offset, unsigned length, uint16_t i_blocksize)
return offset;
}
static inline const char *
static CDIO_INLINE const char *
_cdio_bool_str (bool b)
{
return b ? "yes" : "no";

View File

@@ -49,7 +49,7 @@ EXTRA_DIST = image/Makefile \
FreeBSD/Makefile MSWindows/Makefile \
libcdio.sym
noinst_HEADERS = cdio_assert.h cdio_private.h portable.h
noinst_HEADERS = cdio_assert.h cdio_private.h filemode.h
libcdio_sources = \
_cdio_generic.c \

View File

@@ -31,13 +31,17 @@
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif /*HAVE_UNISTD_H*/
#endif
#include <fcntl.h>
#include <limits.h>
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#include <cdio/sector.h>
#include <cdio/util.h>
@@ -45,12 +49,22 @@
#include "cdio_assert.h"
#include "cdio_private.h"
#include "_cdio_stdio.h"
#include "portable.h"
#include "filemode.h"
#ifndef PATH_MAX
#define PATH_MAX 4096
#endif
/* If available and LFS is enabled, try to use lseek64 */
#if defined(HAVE_LSEEK64) && defined(_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS == 64)
#if defined(_MSC_VER)
#include <io.h>
#endif
#define CDIO_LSEEK lseek64
#else
#define CDIO_LSEEK lseek
#endif
/*!
Eject media -- there's nothing to do here. We always return -2.
Should we also free resources?
@@ -150,13 +164,13 @@ cdio_generic_read_form1_sector (void * user_data, void *data, lsn_t lsn)
/*!
Reads into buf the next size bytes.
Returns -1 on error.
Is in fact libc's lseek().
Is in fact libc's lseek()/lseek64().
*/
off_t
cdio_generic_lseek (void *user_data, off_t offset, int whence)
{
generic_img_private_t *p_env = user_data;
return lseek(p_env->fd, offset, whence);
return CDIO_LSEEK(p_env->fd, offset, whence);
}
/*!

View File

@@ -21,22 +21,50 @@
# define __CDIO_CONFIG_H__ 1
#endif
#ifdef HAVE_STDIO_H
#include <stdio.h>
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif /*HAVE_UNISTD_H*/
#endif
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
#include <cdio/logging.h>
#include <cdio/util.h>
#include "_cdio_stream.h"
#include "_cdio_stdio.h"
/* On 32 bit platforms, fseek can only access streams of 2 GB or less.
Prefer fseeko/fseeko64, that take a 64 bit offset when LFS is enabled */
#if defined(HAVE_FSEEKO64) && defined(_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS == 64)
#define CDIO_FSEEK fseeko64
#elif defined(HAVE_FSEEKO)
#define CDIO_FSEEK fseeko
#else
#define CDIO_FSEEK fseek
#endif
/* Use _stati64 if needed, on platforms that don't have transparent LFS support */
#if defined(HAVE__STATI64) && defined(_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS == 64)
#define CDIO_STAT _stati64
#else
#define CDIO_STAT stat
#endif
#define _STRINGIFY(a) #a
#define STRINGIFY(a) _STRINGIFY(a)
static const char _rcsid[] = "$Id: _cdio_stdio.c,v 1.6 2008/04/22 15:29:11 karl Exp $";
#define CDIO_STDIO_BUFSIZE (128*1024)
@@ -93,7 +121,7 @@ _stdio_free(void *user_data)
}
/*!
Like fseek(3) and in fact may be the same.
Like fseek/fseeko(3) and in fact may be the same.
This function sets the file position indicator for the stream
pointed to by stream. The new position, measured in bytes, is obtained
@@ -108,19 +136,28 @@ _stdio_free(void *user_data)
DRIVER_OP_ERROR is returned and the global variable errno is set to
indicate the error.
*/
static driver_return_code_t
_stdio_seek(void *p_user_data, long i_offset, int whence)
static int
_stdio_seek(void *p_user_data, off_t i_offset, int whence)
{
_UserData *const ud = p_user_data;
int ret;
#if !defined(HAVE_FSEEKO) && !defined(HAVE_FSEEKO64)
/* Detect if off_t is lossy-truncated to long to avoid data corruption */
if ( (sizeof(off_t) > sizeof(long)) && (i_offset != (off_t)((long)i_offset)) ) {
cdio_error ( STRINGIFY(CDIO_FSEEK) " (): lossy truncation detected!");
errno = EFBIG;
return DRIVER_OP_ERROR;
}
#endif
if ( (i_offset=fseek (ud->fd, i_offset, whence)) ) {
cdio_error ("fseek (): %s", strerror (errno));
if ( (ret=CDIO_FSEEK (ud->fd, i_offset, whence)) ) {
cdio_error ( STRINGIFY(CDIO_FSEEK) " (): %s", strerror (errno));
}
return i_offset;
return ret;
}
static long int
static off_t
_stdio_stat(void *p_user_data)
{
const _UserData *const ud = p_user_data;
@@ -145,15 +182,15 @@ _stdio_stat(void *p_user_data)
We do not distinguish between end-of-file and error, and callers
must use feof(3) and ferror(3) to determine which occurred.
*/
static long
_stdio_read(void *user_data, void *buf, long int count)
static ssize_t
_stdio_read(void *user_data, void *buf, size_t count)
{
_UserData *const ud = user_data;
long read;
long read_count;
read = fread(buf, 1, count, ud->fd);
read_count = fread(buf, 1, count, ud->fd);
if (read != count)
if (read_count != count)
{ /* fixme -- ferror/feof */
if (feof (ud->fd))
{
@@ -169,7 +206,7 @@ _stdio_read(void *user_data, void *buf, long int count)
cdio_debug ("fread (): short read and no EOF?!?");
}
return read;
return read_count;
}
/*!
@@ -187,9 +224,9 @@ cdio_stdio_new(const char pathname[])
CdioDataSource_t *new_obj = NULL;
cdio_stream_io_functions funcs = { NULL, NULL, NULL, NULL, NULL, NULL };
_UserData *ud = NULL;
struct stat statbuf;
struct CDIO_STAT statbuf;
if (stat (pathname, &statbuf) == -1)
if (CDIO_STAT (pathname, &statbuf) == -1)
{
cdio_warn ("could not retrieve file info for `%s': %s",
pathname, strerror (errno));

View File

@@ -21,10 +21,18 @@
# define __CDIO_CONFIG_H__ 1
#endif
#ifdef HAVE_STDIO_H
#include <stdio.h>
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#ifdef HAVE_STDARG_H
#include <stdarg.h>
#endif
#include "cdio_assert.h"
/* #define STREAM_DEBUG */
@@ -43,7 +51,7 @@ struct _CdioDataSource {
void* user_data;
cdio_stream_io_functions op;
int is_open;
long position;
off_t position;
};
void
@@ -80,8 +88,8 @@ cdio_stream_destroy(CdioDataSource_t *p_obj)
@return unpon successful completion, return value is positive, else,
the global variable errno is set to indicate the error.
*/
ssize_t
cdio_stream_getpos(CdioDataSource_t* p_obj, /*out*/ ssize_t *i_offset)
off_t
cdio_stream_getpos(CdioDataSource_t* p_obj, /*out*/ off_t *i_offset)
{
if (!p_obj || !p_obj->is_open) return DRIVER_OP_UNINIT;
return *i_offset = p_obj->position;
@@ -140,7 +148,7 @@ _cdio_stream_open_if_necessary(CdioDataSource_t *p_obj)
must use feof(3) and ferror(3) to determine which occurred.
*/
ssize_t
cdio_stream_read(CdioDataSource_t* p_obj, void *ptr, long size, long nmemb)
cdio_stream_read(CdioDataSource_t* p_obj, void *ptr, size_t size, size_t nmemb)
{
long read_bytes;
@@ -168,8 +176,8 @@ cdio_stream_read(CdioDataSource_t* p_obj, void *ptr, long size, long nmemb)
@return unpon successful completion, return value is positive, else,
the global variable errno is set to indicate the error.
*/
ssize_t
cdio_stream_seek(CdioDataSource_t* p_obj, ssize_t offset, int whence)
int
cdio_stream_seek(CdioDataSource_t* p_obj, off_t offset, int whence)
{
if (!p_obj) return DRIVER_OP_UNINIT;
@@ -178,10 +186,11 @@ cdio_stream_seek(CdioDataSource_t* p_obj, ssize_t offset, int whence)
return DRIVER_OP_ERROR;
if (offset < 0) return DRIVER_OP_ERROR;
if (p_obj->position < 0) return DRIVER_OP_ERROR;
if (p_obj->position != offset) {
#ifdef STREAM_DEBUG
cdio_warn("had to reposition DataSource from %ld to %ld!", obj->position, offset);
cdio_warn("had to reposition DataSource from %ld to %ld!", p_obj->position, offset);
#endif
p_obj->position = offset;
return p_obj->op.seek(p_obj->user_data, offset, whence);
@@ -194,7 +203,7 @@ cdio_stream_seek(CdioDataSource_t* p_obj, ssize_t offset, int whence)
Return whatever size of stream reports, I guess unit size is bytes.
On error return -1;
*/
ssize_t
off_t
cdio_stream_stat(CdioDataSource_t *p_obj)
{
if (!p_obj) return -1;

View File

@@ -1,7 +1,6 @@
/*
$Id: _cdio_stream.h,v 1.5 2008/04/22 15:29:11 karl Exp $
Copyright (C) 2003, 2004, 2005, 2006, 2008 Rocky Bernstein <rocky@gnu.org>
Copyright (C) 2003, 2004, 2005, 2006, 2008, 2012
Rocky Bernstein <rocky@gnu.org>
Copyright (C) 2000 Herbert Valerio Riedel <hvr@gnu.org>
This program is free software: you can redistribute it and/or modify
@@ -33,12 +32,12 @@ extern "C" {
typedef int(*cdio_data_open_t)(void *user_data);
typedef long(*cdio_data_read_t)(void *user_data, void *buf, long count);
typedef ssize_t(*cdio_data_read_t)(void *user_data, void *buf, size_t count);
typedef driver_return_code_t(*cdio_data_seek_t)(void *user_data, long offset,
typedef int(*cdio_data_seek_t)(void *user_data, off_t offset,
int whence);
typedef long(*cdio_data_stat_t)(void *user_data);
typedef off_t(*cdio_data_stat_t)(void *user_data);
typedef int(*cdio_data_close_t)(void *user_data);
@@ -65,8 +64,8 @@ extern "C" {
@return unpon successful completion, return value is positive, else,
the global variable errno is set to indicate the error.
*/
ssize_t cdio_stream_getpos(CdioDataSource_t* p_obj,
/*out*/ ssize_t *i_offset);
off_t cdio_stream_getpos(CdioDataSource_t* p_obj,
/*out*/ off_t *i_offset);
CdioDataSource_t *
cdio_stream_new(void *user_data, const cdio_stream_io_functions *funcs);
@@ -88,11 +87,11 @@ extern "C" {
We do not distinguish between end-of-file and error, and callers
must use feof(3) and ferror(3) to determine which occurred.
*/
ssize_t cdio_stream_read(CdioDataSource_t* p_obj, void *ptr, long i_size,
long nmemb);
ssize_t cdio_stream_read(CdioDataSource_t* p_obj, void *ptr, size_t i_size,
size_t nmemb);
/**
Like fseek(3) and in fact may be the same.
Like fseek(3)/fseeko(3) and in fact may be the same.
This function sets the file position indicator for the stream
pointed to by stream. The new position, measured in bytes, is obtained
@@ -107,14 +106,14 @@ extern "C" {
DRIVER_OP_ERROR is returned and the global variable errno is set to
indicate the error.
*/
ssize_t cdio_stream_seek(CdioDataSource_t *p_obj, ssize_t i_offset,
int cdio_stream_seek(CdioDataSource_t *p_obj, off_t i_offset,
int whence);
/**
Return whatever size of stream reports, I guess unit size is bytes.
On error return -1;
*/
ssize_t cdio_stream_stat(CdioDataSource_t *p_obj);
off_t cdio_stream_stat(CdioDataSource_t *p_obj);
/**
Deallocate resources associated with p_obj. After this p_obj is unusable.

View File

@@ -20,10 +20,12 @@
# include <unistd.h>
#endif
#include <stdio.h>
#ifdef HAVE_STDIO_H
# include <stdio.h>
#endif
#ifndef PATH_MAX
#define PATH_MAX 4096
# define PATH_MAX 4096
#endif
#ifndef NULL
@@ -31,12 +33,12 @@
#endif
#ifdef __CYGWIN__
#undef DOSISH
# undef DOSISH
#endif
#if defined __CYGWIN__ || defined DOSISH
#define DOSISH_UNC
#define DOSISH_DRIVE_LETTER
#define FILE_ALT_SEPARATOR '\\'
# define DOSISH_UNC
# define DOSISH_DRIVE_LETTER
# define FILE_ALT_SEPARATOR '\\'
#endif
#ifndef CDIO_FILE_SEPARATOR
@@ -55,7 +57,8 @@
#define skipprefix(path) (path)
#ifndef CharNext /* defined as CharNext[AW] on Windows. */
#if !defined(CharNext) || defined(_MSC_VER) /* defined as CharNext[AW] on Windows. */
# undef CharNext
# define CharNext(p) ((p) + 1)
#endif

View File

@@ -53,7 +53,7 @@
#endif
#include <ctype.h>
#include "portable.h"
#include "filemode.h"
/* reader */
#define DEFAULT_CDIO_DEVICE "videocd.bin"

View File

@@ -57,7 +57,7 @@
#include <ctype.h>
#include "portable.h"
#include "filemode.h"
/* reader */

View File

@@ -27,7 +27,7 @@
#include <cdio/logging.h>
#include "cdio_assert.h"
#include "portable.h"
#include "filemode.h"
static const char _rcsid[] = "$Id: logging.c,v 1.2 2008/04/22 15:29:12 karl Exp $";

View File

@@ -20,7 +20,7 @@
/* Program to read ISO-9660 images. */
#include "util.h"
#include "portable.h"
#include "filemode.h"
#ifdef HAVE_CONFIG_H
# include "config.h"

View File

@@ -23,7 +23,7 @@
# define __CDIO_CONFIG_H__ 1
#endif
#include "portable.h"
#include "filemode.h"
#include <cdio/cdio.h>
#include <cdio/iso9660.h>

View File

@@ -1,6 +1,5 @@
/* $Id: testisocd2.c.in,v 1.2 2008/03/22 18:08:25 karl Exp $
Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Rocky Bernstein
/*
Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2012 Rocky Bernstein
<rocky@gnu.org>
This program is free software: you can redistribute it and/or modify
@@ -23,8 +22,7 @@
# include "config.h"
#endif
#include "portable.h"
#include "filemode.h"
#include <cdio/cdio.h>
#include <cdio/iso9660.h>
#include <cdio/cd_types.h>