summaryrefslogtreecommitdiff
path: root/usr/src/lib/libc/inc
diff options
context:
space:
mode:
authorJerry Jelinek <jerry.jelinek@joyent.com>2020-03-27 11:29:00 +0000
committerJerry Jelinek <jerry.jelinek@joyent.com>2020-03-27 11:29:00 +0000
commit6dcfbbc68f881fbf5c20d25817a0221dfb135170 (patch)
tree40307666f6d7711499061d8c4be75029a6d851e9 /usr/src/lib/libc/inc
parentb0624b90ec9a0c04cca626925beee3ae403457ce (diff)
parentcd62a92d4a964bfe61d35ba2301b69e65e22a509 (diff)
downloadillumos-joyent-6dcfbbc68f881fbf5c20d25817a0221dfb135170.tar.gz
[illumos-gate merge]
commit cd62a92d4a964bfe61d35ba2301b69e65e22a509 7092 Want support for stdio memory streams 12360 fwrite can loop forever on zero byte write 12392 ftello64 doesn't handle ungetc() correctly when unbuffered commit 1470234269f4edea4cbf270cb2475e4988b788d5 12359 Want a means to set the umem mtbf at runtine commit 0ac311bae7f6f50d9ba506b52bd8860f2d68d4ce 12358 Need mbrtowc variant that indicates consumed zero bytes commit d726994754c938f91b6fd7e96b5cab3829615c58 12357 getc/putc_unlocked need to set orientation
Diffstat (limited to 'usr/src/lib/libc/inc')
-rw-r--r--usr/src/lib/libc/inc/file64.h27
-rw-r--r--usr/src/lib/libc/inc/libc.h8
-rw-r--r--usr/src/lib/libc/inc/mtlib.h6
-rw-r--r--usr/src/lib/libc/inc/stdiom.h62
4 files changed, 84 insertions, 19 deletions
diff --git a/usr/src/lib/libc/inc/file64.h b/usr/src/lib/libc/inc/file64.h
index 40504d35ec..1bbc98e2bc 100644
--- a/usr/src/lib/libc/inc/file64.h
+++ b/usr/src/lib/libc/inc/file64.h
@@ -25,6 +25,10 @@
*/
/*
+ * Copyright 2020 Robert Mustacchi
+ */
+
+/*
* This is the header where the internal to libc definition of the FILE
* structure is defined. The exrernal defintion defines the FILE structure
* as an array of longs. This prevents customers from writing code that
@@ -41,8 +45,6 @@
#ifndef _FILE64_H
#define _FILE64_H
-#pragma ident "%Z%%M% %I% %E% SMI"
-
#include <synch.h>
#include <stdio_tag.h>
#include <wchar_impl.h>
@@ -58,8 +60,25 @@ typedef __mbstate_t mbstate_t;
#define rmutex_t mutex_t
+typedef ssize_t (*fread_t)(__FILE *, char *, size_t);
+typedef ssize_t (*fwrite_t)(__FILE *, const char *, size_t);
+typedef off_t (*fseek_t)(__FILE *, off_t, int);
+typedef int (*fclose_t)(__FILE *);
+
+typedef struct {
+ fread_t std_read;
+ fwrite_t std_write;
+ fseek_t std_seek;
+ fclose_t std_close;
+ void *std_data;
+} stdio_ops_t;
+
#ifdef _LP64
+/*
+ * This structure cannot grow beyond its current size of 128 bytes. See the file
+ * lib/libc/port/stdio/README.design for more information.
+ */
struct __FILE_TAG {
unsigned char *_ptr; /* next character from/to here in buffer */
unsigned char *_base; /* the buffer */
@@ -69,7 +88,8 @@ struct __FILE_TAG {
unsigned int _flag; /* the state of the stream */
rmutex_t _lock; /* lock for this structure */
mbstate_t _state; /* mbstate_t */
- char __fill[32]; /* filler to bring size to 128 bytes */
+ stdio_ops_t *_ops; /* Alternate impl ops */
+ char __fill[24]; /* filler to bring size to 128 bytes */
};
#else
@@ -83,6 +103,7 @@ struct xFILEdata {
rmutex_t _lock; /* lock for this structure */
mbstate_t _state; /* mbstate_t */
int _altfd; /* alternate fd if > 255 */
+ stdio_ops_t *_ops; /* Alternate impl ops */
};
#define XFILEINITIALIZER { 0, NULL, RECURSIVEMUTEX, DEFAULTMBSTATE }
diff --git a/usr/src/lib/libc/inc/libc.h b/usr/src/lib/libc/inc/libc.h
index 448523df01..90a2859b33 100644
--- a/usr/src/lib/libc/inc/libc.h
+++ b/usr/src/lib/libc/inc/libc.h
@@ -333,6 +333,14 @@ extern void __throw_constraint_handler_s(const char *_RESTRICT_KYWD, int);
*/
extern void common_panic(const char *, const char *);
+/*
+ * defined in mbrtowc.c.
+ */
+extern size_t mbrtowc_nz_l(wchar_t *_RESTRICT_KYWD, const char *_RESTRICT_KYWD,
+ size_t, mbstate_t *_RESTRICT_KYWD, locale_t);
+extern size_t mbrtowc_nz(wchar_t *_RESTRICT_KYWD, const char *_RESTRICT_KYWD,
+ size_t, mbstate_t *_RESTRICT_KYWD);
+
#ifdef __cplusplus
}
#endif
diff --git a/usr/src/lib/libc/inc/mtlib.h b/usr/src/lib/libc/inc/mtlib.h
index aa5e9e0992..cad6c7ab8d 100644
--- a/usr/src/lib/libc/inc/mtlib.h
+++ b/usr/src/lib/libc/inc/mtlib.h
@@ -27,8 +27,6 @@
#ifndef _MTLIB_H
#define _MTLIB_H
-#pragma ident "%Z%%M% %I% %E% SMI"
-
#include <thread.h>
#ifdef __cplusplus
@@ -66,9 +64,9 @@ extern void assert_no_libc_locks_held(void);
#define _FWRITE _fwrite_unlocked
#define FILENO(s) _fileno(s)
#define FERROR(s) ferror(s)
-#define GETC(s) _getc_unlocked(s)
+#define GETC(s) _getc_internal(s)
#define UNGETC(c, s) _ungetc_unlocked(c, s)
-#define PUTC(c, s) _putc_unlocked(c, s)
+#define PUTC(c, s) _putc_internal(c, s)
#define GETWC(s) getwc(s)
#define PUTWC(c, s) putwc(c, s)
diff --git a/usr/src/lib/libc/inc/stdiom.h b/usr/src/lib/libc/inc/stdiom.h
index 9befb8a3c6..4769231968 100644
--- a/usr/src/lib/libc/inc/stdiom.h
+++ b/usr/src/lib/libc/inc/stdiom.h
@@ -25,7 +25,11 @@
*/
/* Copyright (c) 1988 AT&T */
-/* All Rights Reserved */
+/* All Rights Reserved */
+
+/*
+ * Copyright 2020 Robert Mustacchi
+ */
/*
* stdiom.h - shared guts of stdio
@@ -34,8 +38,6 @@
#ifndef _STDIOM_H
#define _STDIOM_H
-#pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.9 */
-
#include <thread.h>
#include <synch.h>
#include <mtlib.h>
@@ -48,11 +50,18 @@
/*
* The following flags, and the macros that manipulate them, operate upon
* the FILE structure used by stdio. If new flags are required, they should
- * be created in this file. The values of the flags must be differnt from
+ * be created in this file. The values of the flags must be different from
* the currently used values. New macros should be created to use the flags
* so that the compilation mode dependencies can be isolated here.
*/
+/*
+ * The 32-bit version of the stdio FILE has 8 bits for its flags (see
+ * lib/libc/port/stdio/README.design). These 8 bits are used to determine if the
+ * FILE structure is allocated. We define '_DEF_FLAG_MASK' as a means to
+ * indicate this.
+ */
+#define _DEF_FLAG_MASK 0377
#ifdef _LP64
#define _BYTE_MODE_FLAG 0400
#define _WC_MODE_FLAG 01000
@@ -152,7 +161,7 @@ extern int __flsbuf(int, FILE *);
*/
#define _realbufend(iop) ((iop)->_end)
#else
-extern Uchar *_realbufend(FILE *iop);
+extern Uchar *_realbufend(FILE *iop);
extern rmutex_t *_reallock(FILE *iop);
#endif /* _LP64 */
@@ -171,7 +180,7 @@ extern void close_pid(void);
/*
* Internal routines from flush.c
*/
-extern int _file_get(FILE *);
+extern int _get_fd(FILE *);
extern int _file_set(FILE *, int, const char *);
/*
@@ -180,11 +189,8 @@ extern int _file_set(FILE *, int, const char *);
* since 64-bit Solaris is not affected by this.
*/
#ifdef _LP64
-#define GET_FD(iop) ((iop)->_file)
#define SET_FILE(iop, fd) ((iop)->_file = (fd))
#else
-#define GET_FD(iop) \
- (((iop)->__extendedfd) ? _file_get(iop) : (iop)->_magic)
#define SET_FILE(iop, fd) (iop)->_magic = (fd); (iop)->__extendedfd = 0
#endif
@@ -206,7 +212,7 @@ extern int _fileno(FILE *iop);
/*
* Internal routines from _findbuf.c
*/
-extern Uchar *_findbuf(FILE *iop);
+extern Uchar *_findbuf(FILE *iop);
/*
* Internal routine used by fopen.c
@@ -221,12 +227,12 @@ extern size_t _fwrite_unlocked(const void *, size_t, size_t, FILE *);
/*
* Internal routine from getc.c
*/
-int _getc_unlocked(FILE *);
+int _getc_internal(FILE *);
/*
* Internal routine from put.c
*/
-int _putc_unlocked(int, FILE *);
+int _putc_internal(int, FILE *);
/*
* Internal routine from ungetc.c
@@ -260,4 +266,36 @@ extern struct xFILEdata _xftab[];
#endif /* _LP64 */
+/*
+ * A set of stdio routines to allow us to have alternate read, write, lseek, and
+ * close implementations.
+ */
+extern ssize_t _xread(FILE *iop, void *buf, size_t nbytes);
+extern ssize_t _xwrite(FILE *iop, const void *buf, size_t nbytes);
+extern off_t _xseek(FILE *iop, off_t off, int whence);
+extern off64_t _xseek64(FILE *iop, off64_t off, int whence);
+extern int _xclose(FILE *iop);
+extern void *_xdata(FILE *iop);
+extern int _xassoc(FILE *iop, fread_t readf, fwrite_t writef,
+ fseek_t seekf, fclose_t closef, void *data);
+extern void _xunassoc(FILE *iop);
+
+/*
+ * Internal functions from _stdio_flags.c.
+ */
+extern int _stdio_flags(const char *type, int *oflags, int *fflags);
+
+/*
+ * Internal functions from open_memstream.c.
+ */
+extern boolean_t memstream_seek(size_t base, off_t off, size_t max,
+ size_t *nposp);
+extern int memstream_newsize(size_t pos, size_t alloc, size_t nbytes,
+ size_t *nallocp);
+
+/*
+ * Internal function from ftell.o.
+ */
+extern off64_t ftell_common(FILE *iop);
+
#endif /* _STDIOM_H */