gpt4 book ai didi

c - OS X 中的 fp->_IO_write_base 和 fp->_IO_write_end

转载 作者:太空宇宙 更新时间:2023-11-04 10:45:06 26 4
gpt4 key购买 nike

我需要在我的 Mac 上编译一个 C 文件,该文件是在仅假设 Linux 和 GCC 环境下编写的。该文件包含一行

if(fp->_IO_write_base == fp->_IO_write_end)

如果 fp 是指向 FILE 的指针。由于 OS X 不提供 glibc,这段代码无法用 clang 编译,我得到以下错误。

error: no member named '_IO_write_base' in 'struct __sFILE'
if ( fp->_IO_write_base == fp->_IO_write_end )
~ ^
error: no member named '_IO_write_end' in 'struct __sFILE'
if ( fp->_IO_write_base == fp->_IO_write_end )
~ ^

FILE(typedef struct _IO_FILE FILE; in stdio.h)在 Linux 机器上定义在 /usr/include/libio.h 就像

struct _IO_FILE {
int _flags; /* High-order word is _IO_MAGIC; rest is flags. */
#define _IO_file_flags _flags

/* The following pointers correspond to the C++ streambuf protocol. */
/* Note: Tk uses the _IO_read_ptr and _IO_read_end fields directly. */
char* _IO_read_ptr; /* Current read pointer */
char* _IO_read_end; /* End of get area. */
char* _IO_read_base; /* Start of putback+get area. */
char* _IO_write_base; /* Start of put area. */
char* _IO_write_ptr; /* Current put pointer. */
char* _IO_write_end; /* End of put area. */
char* _IO_buf_base; /* Start of reserve area. */
char* _IO_buf_end; /* End of reserve area. */
/* The following fields are used to support backing up and undo. */
char *_IO_save_base; /* Pointer to start of non-current get area. */
char *_IO_backup_base; /* Pointer to first valid character of backup area */
char *_IO_save_end; /* Pointer to end of non-current get area. */

struct _IO_marker *_markers;

struct _IO_FILE *_chain;

int _fileno;
#if 0
int _blksize;
#else
int _flags2;
#endif
_IO_off_t _old_offset; /* This used to be _offset but it's too small. */

#define __HAVE_COLUMN /* temporary */
/* 1+column number of pbase(); 0 is unknown. */
unsigned short _cur_column;
signed char _vtable_offset;
char _shortbuf[1];

/* char* _save_gptr; char* _save_egptr; */

_IO_lock_t *_lock;
#ifdef _IO_USE_OLD_IO_FILE
};

但在 OS X 中,FILEstdio.h 中定义如下。您可以看到 _IO_write_base_IO_write_end 是特定于 glibc 的,它们不存在于 OS X 的 C 库中。

typedef struct __sFILE {
unsigned char *_p; /* current position in (some) buffer */
int _r; /* read space left for getc() */
int _w; /* write space left for putc() */
short _flags; /* flags, below; this FILE is free if 0 */
short _file; /* fileno, if Unix descriptor, else -1 */
struct __sbuf _bf; /* the buffer (at least 1 byte, if !NULL) */
int _lbfsize; /* 0 or -_bf._size, for inline putc */

/* operations */
void *_cookie; /* cookie passed to io functions */
int (*_close)(void *);
int (*_read) (void *, char *, int);
fpos_t (*_seek) (void *, fpos_t, int);
int (*_write)(void *, const char *, int);

/* separate buffer for long sequences of ungetc() */
struct __sbuf _ub; /* ungetc buffer */
struct __sFILEX *_extra; /* additions to FILE to not break ABI */
int _ur; /* saved _r when _r is counting ungetc data */

/* tricks to meet minimum requirements even when malloc() fails */
unsigned char _ubuf[3]; /* guarantee an ungetc() buffer */
unsigned char _nbuf[1]; /* guarantee a getc() buffer */

/* separate buffer for fgetln() when line crosses buffer boundary */
struct __sbuf _lb; /* buffer for fgetln() */

/* Unix stdio files get aligned to block boundaries on fseek() */
int _blksize; /* stat.st_blksize (may be != _bf._size) */
fpos_t _offset; /* current lseek offset (see WARNING) */
} FILE;

我想知道如何在 Linux 和 OS X 上编译代码。

最佳答案

那是糟糕的代码。 FILE * 的内部是特定于实现的,因此 FILE * 需要被视为不透明的——您不能在其中使用任何内容。因为在某些平台上,它实际上是不透明的,您无法访问内部结构。

您必须弄清楚代码试图做什么,并重写它

关于c - OS X 中的 fp->_IO_write_base 和 fp->_IO_write_end,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33436569/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com