4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * MKS header file. Defines that make programming easier for us.
31 * Includes MKS-specific things and posix routines.
33 * Copyright 1985, 1993 by Mortice Kern Systems Inc. All rights reserved.
35 * $Header: /rd/h/rcs/mks.h 1.233 1995/09/28 19:45:19 mark Exp $
42 * This should be a feature test macro defined in the Makefile or
50 * Write function declarations as follows:
51 * extern char *function ANSI((char *cp, int flags, NODE *np));
52 * Expansion of this happens only when __STDC__ is set.
56 #define _VOID void /* Used in VOID *malloc() */
62 #define _VOID char /* Used in _VOID *malloc() */
66 # define STATIC static /* Used for function definition */
71 # define STATREF static
73 # define STATREF /* Used in local function forward declaration */
77 #define LEXTERN extern /* Library external reference */
78 #define LDEFN /* Define Loadable library entry */
80 typedef void (*_sigfun_t
)(int);
86 #include <sys/stat.h> /* required for m_samefile() prototype. */
91 #if M_TFGETC || M_STTY_CC
96 # error "You must define M_LIBDIR in mkslocal.h"
100 # error "You must define M_ETCDIR in mkslocal.h"
104 # error "You must define M_SPOOLDIR in mkslocal.h"
108 # error "You must define M_MANPATH in mkslocal.h"
111 #if defined(I18N) && !defined(M_NLSDIR)
112 # error "You must define M_NLSDIR in mkslocal.h"
115 #if (defined(M_I18N_MKS_FULL) || defined(M_I18N_MKS_XPG)) && !defined(I18N)
116 # error I18N must be defined
119 /* P_tmpdir - used by tmpnam.c and tempnam.c.
120 * Could be in <stdio.h>. But in case it is not ..
124 # error M_TMPDIR must be defined in mkslocal.h
126 # define P_tmpdir M_TMPDIR
127 #endif /* P_tmpdir */
129 /* L_cuserid - used by cuserid.c
130 * Could be in <stdio.h>. But in case it is not ..
134 # error M_L_CUSERID must be defined in mkslocal.h
136 # define L_cuserid M_L_CUSERID
137 #endif /* L_cuserid */
140 LEXTERN
char *m_audmode (int, int);
141 #if !defined(M_AUDITW1) || !defined(M_AUDITW2)
142 # error "With M_AUDIT set, you must define M_AUDITW1 and M_AUDITW2"
147 # error "You must define M_CS_PATH in mkslocal.h"
151 # error "You must define M_CS_SHELL in mkslocal.h"
154 #ifndef M_SH_USER_FDS
156 * default number of user file descriptors to be used in the shell
157 * Must be >= 10, should be <= OPEN_MAX/2.
159 #define M_SH_USER_FDS 10
160 #endif /*M_SH_USER_FDS*/
162 #ifndef M_SH_MAX_FUNCTION_EVAL_DEPTH
163 #define M_SH_MAX_FUNCTION_EVAL_DEPTH 100
167 #define M_MANPAGER "more -A -s"
170 /* set up alert and verticalTab characters - This assumes an ANSI-C compiler */
177 # define M_ESCAPE '\033' /* default to ASCII code for <ESC> */
181 /* if SETVBUF not previously defined, then use default ANSI-C definition */
182 # define SETVBUF setvbuf
186 /* if M_NULL defined in <mkslocal.h> then want to redefine NULL */
188 #define NULL (M_NULL)
192 * Useful additions to sys/stat.h.
195 #define S_IRALL (S_IRUSR|S_IRGRP|S_IROTH)
198 #define S_IWALL (S_IWUSR|S_IWGRP|S_IWOTH)
201 #define S_IXALL (S_IXUSR|S_IXGRP|S_IXOTH)
204 #ifndef M_DEFMODE /* Default directory creation mode */
205 #define M_DEFMODE ((mode_t)S_IRALL|S_IWALL)/* Default file creation mode*/
208 #define M_DIRMODE ((mode_t)S_IRALL|S_IWALL|S_IXALL)
212 #define M_FLDSEP ':' /* UNIX field separator for passwd, PATH */
216 #define M_TTYNAME "/dev/tty"
220 #define M_NULLNAME "/dev/null"
224 #define M_FSDELIM(c) ((c)=='/')
228 #define M_DRDELIM(c) (0)
232 #define M_DIRSTAT(name, dp, sb) stat((name), (sb))
236 #define M_HIDDEN(dirp, dp) ((dp)->d_name[0] == '.')
239 #ifndef M_FSMOUNT /* for use by setmnt routine */
240 #define M_FSMOUNT M_ETCDIR(mtab)
243 #ifndef M_FSALL /* for use by setmnt routine */
244 #define M_FSALL M_ETCDIR(fstab)
247 #ifndef M_NLSCHARMAP /* Default charmap file for localedef */
248 #define M_NLSCHARMAP M_NLSDIR(charmap/ISO_8859-1)
251 #ifndef M_POSIXPATH /* used when I18N undefined, default posix path */
252 #define M_POSIXPATH M_NLSDIR(locale/POSIX)
256 #define M_ISEOV(error) 0
259 #ifndef M_IS_NATIVE_LOCALE
260 #define M_IS_NATIVE_LOCALE(s) (strcmp(s, "POSIX")==0 || strcmp(s, "C")==0)
264 #define M_FSCLOSE(fp)
267 #ifndef ROOTUID /* default superuser uid = 0 */
271 #ifndef ROOTGID /* default superuser gid = 0 */
275 #ifndef M_GROUP_PASSWD
276 #define M_GROUP_PASSWD(grp) (grp->gr_passwd)
282 * define the expected max length of a printed number. (used in awk)
283 * This should be the longest expected size for any type of number
284 * ie. float, long etc.
285 * This number is used to calculate the approximate
286 * number of bytes needed to hold the number.
289 #endif /* M_NUMSIZE */
292 * VARARG[12345]: declare variadic functions.
293 * Expands to either a standard C prototype or a K&R declaration.
296 * #include <stdarg.h>
298 * fprintf VARARG2(FILE*, fp, char*, fmt)
303 * cp = va_arg(ap, char*);
309 #define VARARG1(type, name) (type name, ...)
310 #define VARARG2(t1, n1, t2, n2) (t1 n1, t2 n2, ...)
311 #define VARARG3(t1, n1, t2, n2, t3, n3) (t1 n1, t2 n2, t3 n3, ...)
312 #define VARARG4(t1, n1, t2, n2, t3, n3, t4, n4) \
313 (t1 n1, t2 n2, t3 n3, t4 n4, ...)
314 #define VARARG5(t1, n1, t2, n2, t3, n3, t4, n4, t5, n5) \
315 (t1 n1, t2 n2, t3 n3, t4 n4, t5 n5, ...)
317 #define VARARG1(type, name) (name, va_alist) type name; int va_alist
318 #define VARARG2(t1, n1, t2, n2) (n1, n2, va_alist) t1 n1; t2 n2; int va_alist
319 #define VARARG3(t1, n1, t2, n2, t3, n3) (n1, n2, n3, va_alist) \
320 t1 n1; t2 n2; t3 n3; int va_alist
321 #define VARARG4(t1, n1, t2, n2, t3, n3, t4, n4) (n1, n2, n3, n4, va_alist) \
322 t1 n1; t2 n2; t3 n3; t4 n4; int va_alist
323 #define VARARG5(t1, n1, t2, n2, t3, n3, t4, n4, t5, n5) \
324 (n1, n2, n3, n4, n5, va_alist) \
325 t1 n1; t2 n2; t3 n3; t4 n4; t5 n5; int va_alist
331 * MKS-specific library entry points.
333 extern char *_cmdname
;
334 LEXTERN
char *basename (char *);
335 LEXTERN
void crc16 (ushort
*, ushort
);
336 LEXTERN
void crcccitt (ushort
*, ushort
);
337 LEXTERN
int eprintf (const char *, ...);
338 LEXTERN
void eputs (const char *);
339 LEXTERN pid_t
fexecve (const char *, char *const *, char *const *);
340 LEXTERN pid_t
fexecvp (const char *, char *const *);
341 LEXTERN pid_t
fexecvep (const char *, char *const *, char *const *);
342 LEXTERN
int execvep (const char *, char *const *, char *const *);
343 LEXTERN
int isabsname (const char *);
344 LEXTERN
const char *m_cescape (wint_t);
345 LEXTERN
int m_escapec (char **);
346 LEXTERN
const char *m_toprint (wint_t);
348 LEXTERN
int m_stty_cc (cc_t
* cp
, char *str
);
350 LEXTERN
char *m_cmdname (char *);
351 LEXTERN
char *m_strmode (mode_t
);
352 LEXTERN
char *m_readmode (const char *);
353 LEXTERN
char *m_readnum (long *, char *, char **, int);
354 LEXTERN
char *m_readunum (unsigned long *, char *, char **, int);
355 LEXTERN mode_t
m_getmode (mode_t
);
356 LEXTERN
int m_wallow (int, const char *);
357 LEXTERN
char *m_pathcat (const char *, const char *);
358 LEXTERN
void m_sigcleanup (void (*__handler
)(int __signo
) );
359 LEXTERN
void m_defaction (int __signo
);
360 LEXTERN
char *m_strdup (const char *s
);
361 LEXTERN
int m_stricmp (const char *, const char *);
362 LEXTERN
char *m_self (int, char *, char *);
363 LEXTERN
int m_grouplist (char *user
, gid_t
*gidlist
[]);
364 LEXTERN
int m_setgroups (int gidsetsize
, gid_t grouplist
[]);
365 LEXTERN uint
m_binsrch (uint n
, int (*cmp
)(uint i
));
366 LEXTERN
char *m_dirname (const char*);
367 LEXTERN
char *m_confstr (int);
369 LEXTERN
void m_crcposix (ulong
*, const uchar
*, size_t);
370 LEXTERN
int m_setprio (int, unsigned int, int);
371 LEXTERN
int m_getprio (int, unsigned int);
372 LEXTERN
int m_incrnice (int, unsigned int, int);
373 LEXTERN
char *m_devname (dev_t
);
374 LEXTERN
char *m_mountdir (const char *);
375 LEXTERN
int m_absname(char *, char *, char *, size_t);
376 LEXTERN
int m_samefile(char *, struct stat
*, char *, struct stat
*);
378 /* __m_system() : alternate interface into system() */
379 LEXTERN
int __m_system (const char *, const char *, const char *);
382 /* conversion routines - between single byte and UNICODE (wide) strings.
383 * These return a pointer to malloc'd memory.
384 * It is the caller's responsiblity to free() it, if necessary
385 * These are for use primarily on NT
387 extern char *m_unicodetosb(const wchar_t*);
388 extern wchar_t *m_sbtounicode(const char*);
392 * things that could go into an "m_stdio.h"
395 /* m_unlink() : alternate unlink() for use with vendor-provided
396 * libraries that do not have a satisfactory unlink() */
398 #define m_unlink(s) unlink(s)
401 /* __m_popen() : alternate interface into popen() */
402 LEXTERN
FILE *__m_popen (const char *, const char *,
403 const char *, const char *);
404 LEXTERN
FILE *__m_popenvp (const char *mode
, const char *shell
,
405 char const * const *args
);
408 LEXTERN
int m_tfgetc (FILE *fp
, struct termios
*tp
);
410 #define m_tfgetc(fp,tp) fgetc(fp)
413 /* m_fsopen() - special routine for curses */
414 LEXTERN
FILE *m_fsopen (char *, size_t, const char *, FILE *);
416 #ifndef M_FFLUSH_NOT_POSIX_1
417 # define m_fflush fflush
419 LEXTERN
int m_fflush (FILE *);
422 /* m_fgets return values */
424 M_FGETS_OK
, /* Normal return */
426 * Regular EOF (same as NULL from fgets).
427 * Buffer is *untouched*.
430 * Short input (buf[strlen(buf)-1] != '\n')
431 * This is a trailing line, without a newline at the
432 * end of the file. The buffer is valid, ending in
433 * a \0, with no newline. The case of terminal input
434 * ending with an EOF in the middle of the line will
435 * restart -- typing two EOF's will result in this
439 * Line too long: newline not found within len bytes
440 * (buf[len-1] != '\n').
441 * At this point, while((c=getc(fp)) != '\n') ...
442 * is a valid method to get the rest of the line.
445 * Input contained an invalid character (e.g. \0)
446 * Buffer contents *undefined*.
449 * A system call returned an error, errno is set.
450 * Buffer contents *undefined*.
453 LEXTERN
int m_fgets (char *, size_t, FILE *);
456 * end of things that could go into an "m_stdio.h"
459 LEXTERN
int m_winsize (int *, int *);
460 LEXTERN
char *m_cuserid ();
462 /* m_ctype: generic character classification */
463 typedef int m_ctype_t
; /* ctype property */
464 LEXTERN m_ctype_t
m_ctype (const char *property
);
465 LEXTERN
int m_isctype (int c
, m_ctype_t ctype
);
466 LEXTERN
char *m_readdate (char *, time_t *, int);
468 #ifndef M_READDATE_SYSV
469 #define M_READDATE_SYSV 0
471 #ifndef M_READDATE_BSD
472 #define M_READDATE_BSD 1
476 LEXTERN _VOID
*m_malloc (size_t size
);
478 # define m_malloc(size) malloc(size)
482 LEXTERN _VOID
*m_realloc (void* ptr
, size_t size
);
484 # define m_realloc realloc
488 #define m_namemax(path) NAME_MAX
490 LEXTERN
int m_namemax (char *path
);
494 #define m_pathmax(path) PATH_MAX
496 LEXTERN
int m_pathmax (char *path
);
497 #endif /* PATH_MAX */
500 LEXTERN
int m_devbin (int fd
); /* begin raw I/O transfer */
501 LEXTERN
void m_devstd (int fd
, int mode
); /* end raw I/O transfer */
503 # define m_devbin(fd) 0
504 # define m_devstd(fd, mode)
508 #define m_setbinary(fp)
509 #endif /*m_setbinary*/
511 #ifndef M_PRIO_PROCESS
512 #define M_PRIO_PROCESS 0
515 #define M_PRIO_PGRP 1
518 #define M_PRIO_USER 2
521 /* m_wallow type values */
523 #define MWA_NO 0 /* Deny talk, write */
526 #define MWA_YES 1 /* Allow talk, write */
529 #define MWA_TEST 2 /* Test for YES/NO */
532 /* Interface for compression (m_cm_*) and decompression (m_dc_*) */
533 LEXTERN
int m_cm_open (int (*wrtfn
) (const uchar
*,int), int);
534 LEXTERN
int m_cm_write (const uchar
*, int);
535 LEXTERN
int m_cm_close (int);
536 LEXTERN
char *m_cm_error (void);
537 LEXTERN
int m_dc_open (ssize_t (*rdfn
)(uchar
*, int));
538 LEXTERN ssize_t
m_dc_read (uchar
*, size_t);
539 LEXTERN
int m_dc_close (int);
540 LEXTERN
char *m_dc_error (void);
542 LEXTERN
int m_mkpardir (char *);
545 * Some UNIX routines that aren't in SVID
547 LEXTERN
void cfree (void *, size_t, size_t);
548 LEXTERN
void swaw (const short *, short *, int);
550 /* Some dos routines we sometimes want from posix utilities */
551 LEXTERN
void _uttoof (time_t, ushort
*, ushort
*);
552 LEXTERN
time_t _oftout (ushort
, ushort
);
556 #define m_setenv() environ
559 #ifdef M_NON_STATIC_GETENV
560 #define __m_getenv getenv
562 LEXTERN
char *__m_getenv(char const *); /* Library safe getenv() */
565 #ifndef M_CRON_MAILER
567 * Default case: assume only POSIX.2 mailx is available.
568 * Must be careful when cron sends output to mailx.
569 * We must ensure that lines with leading '~' are escaped
570 * so mailx doesn't interpret these lines
571 * This string MUST include a trailing space character.
573 #define M_CRON_MAILER "sed -e s/^~/~~/ | mailx "
577 * m_cp() - copy a file in an O/S specific way. See m_cp.3
585 /* processing flags */
586 #define M_CP_PRESERVE 1
589 * MKS MEMORY MANIPULATIONS:
590 * Specific to MKS and non-portable.
592 LEXTERN _VOID
*membtst (const char *s
, size_t m
, int c
);
595 #define memLchr memchr
596 #define memSLccpy memccpy
597 #define memLbtst membtst
598 #define memLset memset
599 #define memLLcpy memcpy
600 #define memLLrlcpy memrlcpy
601 #define memLLcmp memcmp
603 /* for machines with small data models (e.g PC's - DOS, OS2) */
604 LEXTERN
void far
*memLchr (const void far
*s
, int c
, size_t n
);
605 LEXTERN
void *memSLccpy (_VOID
*s1
, const _VOID far
*s2
, int, size_t n
);
606 LEXTERN
void far
*memLbtst (const char far
*s
, size_t m
, int n
);
607 LEXTERN
void far
*memLset (void far
*s
, int c
, size_t n
);
608 LEXTERN
void far
*memLsetl (void far
*p
, int value
, long count
);
609 LEXTERN
void far
*memLLcpy (void far
*s1
, const void far
*s2
, size_t n
);
610 LEXTERN
void far
*memLLrlcpy (void far
*s1
, const void far
*s2
, size_t);
611 LEXTERN
int memLLcmp (const void far
*s1
,const void far
*s2
,size_t n
);
615 /* mks error handling routines */
617 LEXTERN
void m_error (const char * fmt
, ...);
618 LEXTERN
void m_errorexit (const char *fmt
, va_list args
);
619 LEXTERN
void m_errorret (const char *fmt
, va_list args
);
620 LEXTERN
void m_errorjmp (const char *fmt
, va_list args
);
621 LEXTERN
void m_errornull (const char *fmt
, va_list args
);
622 LEXTERN
void (*m_errorfn
) (const char *fmt
, va_list args
);
623 #define M_ERROR(fn) void (*m_errorfn) (const char *fmt, va_list args) = fn
626 * The filesystem type and attribute routine
629 #define m_fstype(path) M_FSTYPE_POSIX
632 /* File system types */
633 #define M_FSTYPE_MASK 0x1
634 #define M_FSTYPE_POSIX 0
635 #define M_FSTYPE_FAT 1
637 /* File system attributes */
638 #define M_FSATTR_NO_LEADING_DOT 0x08
639 #define M_FSATTR_ONE_DOT 0x10
640 #define M_FSATTR_SHORT_FILENAME 0x20
641 #define M_FSATTR_SHORT_EXT 0x40
642 #define M_FSATTR_LOWER_CASE 0x80
644 /* This one should be ifdef'ed on something else */
645 #ifndef M_FNMATCH_DUALCASE
646 #define m_get_original_filename_case(path) /* nil */
650 * m_tempname() generates a filename for a temp file using "code"
654 #define m_tempname(code) tempnam(__m_getenv("TMPDIR"), (code))
656 char *m_tempname(char const *code
);
660 * __m_getopt() alternate "stateless" entry into getopt().
663 struct getopt_state
{
664 char *optarg
; /* Argument */
665 int optind
; /* Index into argv */
666 int opterr
; /* Print error message */
667 int optopt
; /* Invalid option */
668 int index
; /* argv[optind] index */
670 mbstate_t st
; /* State of argv[optind][index] */
674 int __m_getopt(int argc
, char * const *argv
, char const *optstring
,
675 struct getopt_state
*state
);
679 /* Any overrides etcetera for a particular system can go in here */
680 #include <mksextra.h>
681 #endif /* M_MKSEXTRA_H */
683 #endif /* __M_MKS_H__ */