fix Linux compile issues
- include stubs for Solaris specific functionality - include some missing standard headers - guard Solaris specific constructs with preprocessor conditionals - fix pointer-to-int-cast undefined behavior
This commit is contained in:
parent
c0dfa85aa1
commit
43a5295e69
|
@ -46,6 +46,7 @@
|
||||||
#include <libintl.h>
|
#include <libintl.h>
|
||||||
#include <mk/defs.h>
|
#include <mk/defs.h>
|
||||||
#include <mksh/misc.h> /* retmem_mb() */
|
#include <mksh/misc.h> /* retmem_mb() */
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
struct ranlib {
|
struct ranlib {
|
||||||
union {
|
union {
|
||||||
|
|
|
@ -43,13 +43,18 @@
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#include <libintl.h>
|
#include <libintl.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#if defined(sun) || defined(__sun)
|
||||||
|
// XXX really needed, even on Solaris?
|
||||||
#include <stropts.h>
|
#include <stropts.h>
|
||||||
|
#else
|
||||||
|
#endif
|
||||||
#include <sys/errno.h>
|
#include <sys/errno.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/utsname.h> /* uname() */
|
#include <sys/utsname.h> /* uname() */
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <unistd.h> /* close() */
|
#include <unistd.h> /* close() */
|
||||||
|
#include <comp/namelen.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Defined macros
|
* Defined macros
|
||||||
|
|
27
bin/main.cc
27
bin/main.cc
|
@ -48,14 +48,23 @@
|
||||||
#include <sys/errno.h> /* ENOENT */
|
#include <sys/errno.h> /* ENOENT */
|
||||||
#include <sys/stat.h> /* fstat() */
|
#include <sys/stat.h> /* fstat() */
|
||||||
#include <fcntl.h> /* open() */
|
#include <fcntl.h> /* open() */
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
|
#if defined(sun) || defined(__sun)
|
||||||
# include <sys/systeminfo.h> /* sysinfo() */
|
# include <sys/systeminfo.h> /* sysinfo() */
|
||||||
|
#else
|
||||||
|
#include <sys/sysinfo.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <sys/types.h> /* stat() */
|
#include <sys/types.h> /* stat() */
|
||||||
#include <sys/wait.h> /* wait() */
|
#include <sys/wait.h> /* wait() */
|
||||||
#include <unistd.h> /* execv(), unlink(), access() */
|
#include <unistd.h> /* execv(), unlink(), access() */
|
||||||
#include <vroot/report.h> /* report_dependency(), get_report_file() */
|
#include <vroot/report.h> /* report_dependency(), get_report_file() */
|
||||||
|
|
||||||
|
#include <libintl.h> // gettext()
|
||||||
|
|
||||||
|
#include <comp/progname.h>
|
||||||
|
|
||||||
// From read2.cc
|
// From read2.cc
|
||||||
extern Name normalize_name(register wchar_t *name_string, register int length);
|
extern Name normalize_name(register wchar_t *name_string, register int length);
|
||||||
|
|
||||||
|
@ -69,7 +78,7 @@ extern void job_adjust_fini();
|
||||||
#define LD_SUPPORT_ENV_VAR_32 "SGS_SUPPORT_32"
|
#define LD_SUPPORT_ENV_VAR_32 "SGS_SUPPORT_32"
|
||||||
#define LD_SUPPORT_ENV_VAR_64 "SGS_SUPPORT_64"
|
#define LD_SUPPORT_ENV_VAR_64 "SGS_SUPPORT_64"
|
||||||
#define LD_SUPPORT_MAKE_LIB "libmakestate.so.1"
|
#define LD_SUPPORT_MAKE_LIB "libmakestate.so.1"
|
||||||
#ifdef __i386
|
#if defined(__i386) || defined(__x86_64__)
|
||||||
#define LD_SUPPORT_MAKE_ARCH "i386"
|
#define LD_SUPPORT_MAKE_ARCH "i386"
|
||||||
#elif __sparc
|
#elif __sparc
|
||||||
#define LD_SUPPORT_MAKE_ARCH "sparc"
|
#define LD_SUPPORT_MAKE_ARCH "sparc"
|
||||||
|
@ -197,7 +206,11 @@ main(int argc, char *argv[])
|
||||||
|
|
||||||
struct stat out_stat, err_stat;
|
struct stat out_stat, err_stat;
|
||||||
hostid = gethostid();
|
hostid = gethostid();
|
||||||
|
#if defined(sun) || defined(__sun)
|
||||||
bsd_signals();
|
bsd_signals();
|
||||||
|
#else
|
||||||
|
// XXX necessary on linux?
|
||||||
|
#endif
|
||||||
|
|
||||||
(void) setlocale(LC_ALL, "");
|
(void) setlocale(LC_ALL, "");
|
||||||
|
|
||||||
|
@ -475,7 +488,11 @@ main(int argc, char *argv[])
|
||||||
/*
|
/*
|
||||||
* Enable interrupt handler for alarms
|
* Enable interrupt handler for alarms
|
||||||
*/
|
*/
|
||||||
|
#if defined(sun) || defined(__sun)
|
||||||
(void) bsd_signal(SIGALRM, (SIG_PF)doalarm);
|
(void) bsd_signal(SIGALRM, (SIG_PF)doalarm);
|
||||||
|
#else
|
||||||
|
(void) bsd_signal(SIGALRM, doalarm);
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check if make should report
|
* Check if make should report
|
||||||
|
@ -1596,7 +1613,13 @@ make_install_prefix(void)
|
||||||
char origin[PATH_MAX];
|
char origin[PATH_MAX];
|
||||||
char *dir;
|
char *dir;
|
||||||
|
|
||||||
if ((ret = readlink("/proc/self/path/a.out", origin,
|
if ((ret = readlink(
|
||||||
|
#if defined(sun) || defined(__sun)
|
||||||
|
"/proc/self/path/a.out",
|
||||||
|
#else
|
||||||
|
"/proc/self/exe",
|
||||||
|
#endif
|
||||||
|
origin,
|
||||||
PATH_MAX - 1)) < 0)
|
PATH_MAX - 1)) < 0)
|
||||||
fatal("failed to read origin from /proc\n");
|
fatal("failed to read origin from /proc\n");
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,10 @@
|
||||||
#include <stdarg.h> /* va_list, va_start(), va_end() */
|
#include <stdarg.h> /* va_list, va_start(), va_end() */
|
||||||
#include <vroot/report.h> /* SUNPRO_DEPENDENCIES */
|
#include <vroot/report.h> /* SUNPRO_DEPENDENCIES */
|
||||||
#include <libintl.h>
|
#include <libintl.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include <comp/progname.h>
|
||||||
|
|
||||||
extern void job_adjust_fini();
|
extern void job_adjust_fini();
|
||||||
|
|
||||||
|
|
|
@ -46,8 +46,11 @@
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
|
#include <semaphore.h>
|
||||||
|
|
||||||
#include <libintl.h>
|
#include <libintl.h>
|
||||||
|
|
||||||
|
#include <comp/namelen.h>
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -252,7 +255,12 @@ execute_parallel(Property line, Boolean waitflg, Boolean local)
|
||||||
#include <sys/ipc.h> /* ftok() */
|
#include <sys/ipc.h> /* ftok() */
|
||||||
#include <sys/shm.h> /* shmget(), shmat(), shmdt(), shmctl() */
|
#include <sys/shm.h> /* shmget(), shmat(), shmdt(), shmctl() */
|
||||||
#include <semaphore.h> /* sem_init(), sem_trywait(), sem_post(), sem_destroy() */
|
#include <semaphore.h> /* sem_init(), sem_trywait(), sem_post(), sem_destroy() */
|
||||||
|
#if defined(sun) || defined(__sun)
|
||||||
#include <sys/loadavg.h> /* getloadavg() */
|
#include <sys/loadavg.h> /* getloadavg() */
|
||||||
|
#else
|
||||||
|
#include <stdlib.h> // getloadavg()
|
||||||
|
#define LOADAVG_1MIN 0
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* adjust_pmake_max_jobs (int pmake_max_jobs)
|
* adjust_pmake_max_jobs (int pmake_max_jobs)
|
||||||
|
|
|
@ -43,6 +43,7 @@
|
||||||
#include <unistd.h> /* read(), unlink() */
|
#include <unistd.h> /* read(), unlink() */
|
||||||
#include <libintl.h>
|
#include <libintl.h>
|
||||||
|
|
||||||
|
#include <comp/progname.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* typedefs & structs
|
* typedefs & structs
|
||||||
|
|
|
@ -39,6 +39,8 @@
|
||||||
#include <stdarg.h> /* va_list, va_start(), va_end() */
|
#include <stdarg.h> /* va_list, va_start(), va_end() */
|
||||||
#include <libintl.h>
|
#include <libintl.h>
|
||||||
|
|
||||||
|
#include <comp/progname.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Defined macros
|
* Defined macros
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -39,6 +39,11 @@
|
||||||
#include <errno.h> /* errno */
|
#include <errno.h> /* errno */
|
||||||
#include <locale.h> /* MB_CUR_MAX */
|
#include <locale.h> /* MB_CUR_MAX */
|
||||||
|
|
||||||
|
#if defined(sun) || defined(__sun)
|
||||||
|
#else
|
||||||
|
#include <libintl.h> // gettext()
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Defined macros
|
* Defined macros
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
|
#if defined(sun) || defined(__sun)
|
||||||
|
|
||||||
#ifndef __cplusplus
|
#ifndef __cplusplus
|
||||||
typedef void (*SIG_PF) (int);
|
typedef void (*SIG_PF) (int);
|
||||||
|
@ -45,3 +46,5 @@ extern void (*bsd_signal(int, void (*) (int))) (int);
|
||||||
extern void bsd_signals(void);
|
extern void bsd_signals(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
@ -294,7 +294,11 @@ extern long int hostid;
|
||||||
* Declarations of system defined variables
|
* Declarations of system defined variables
|
||||||
*/
|
*/
|
||||||
/* On linux this variable is defined in 'signal.h' */
|
/* On linux this variable is defined in 'signal.h' */
|
||||||
|
#if defined(sun) || defined(__sun)
|
||||||
extern char *sys_siglist[];
|
extern char *sys_siglist[];
|
||||||
|
#else
|
||||||
|
#include <signal.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Declarations of system supplied functions
|
* Declarations of system supplied functions
|
||||||
|
@ -353,7 +357,9 @@ extern wchar_t *getmem_wc(register int size);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(sun) || defined(__sun)
|
||||||
extern char *getwd(char *);
|
extern char *getwd(char *);
|
||||||
|
#endif
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -36,6 +36,9 @@
|
||||||
#include <errno.h> /* errno */
|
#include <errno.h> /* errno */
|
||||||
|
|
||||||
#include <wctype.h>
|
#include <wctype.h>
|
||||||
|
#include <wchar.h>
|
||||||
|
|
||||||
|
#include <comp/timestruc_t.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A type and some utilities for boolean values
|
* A type and some utilities for boolean values
|
||||||
|
@ -861,7 +864,12 @@ extern Boolean do_not_exec_rule; /* `-n' */
|
||||||
extern Boolean dollarget_seen;
|
extern Boolean dollarget_seen;
|
||||||
extern Boolean dollarless_flag;
|
extern Boolean dollarless_flag;
|
||||||
extern Name dollarless_value;
|
extern Name dollarless_value;
|
||||||
|
// On Linux, environ is declared with C linkage in unistd.h
|
||||||
|
// if _GNU_SOURCE is defined. Declaring it with C linkage here
|
||||||
|
// should also be fine under Solaris.
|
||||||
|
extern "C" {
|
||||||
extern char **environ;
|
extern char **environ;
|
||||||
|
}
|
||||||
extern Envvar envvar;
|
extern Envvar envvar;
|
||||||
extern int exit_status;
|
extern int exit_status;
|
||||||
extern wchar_t *file_being_read;
|
extern wchar_t *file_being_read;
|
||||||
|
|
|
@ -93,7 +93,13 @@ redirect_io(char *stdout_file, char *stderr_file)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
#if defined(sun) || defined(__sun)
|
||||||
(void) closefrom(3);
|
(void) closefrom(3);
|
||||||
|
#else
|
||||||
|
// XXX not available on Linux
|
||||||
|
// if necessary, could provide a compatibility function that
|
||||||
|
// iterates over /proc/$(getpid())/fd ...
|
||||||
|
#endif
|
||||||
if ((i = my_open(stdout_file,
|
if ((i = my_open(stdout_file,
|
||||||
O_WRONLY | O_CREAT | O_TRUNC | O_DSYNC,
|
O_WRONLY | O_CREAT | O_TRUNC | O_DSYNC,
|
||||||
S_IREAD | S_IWRITE)) < 0) {
|
S_IREAD | S_IWRITE)) < 0) {
|
||||||
|
|
|
@ -49,6 +49,7 @@
|
||||||
#include <sys/wait.h> /* wait() */
|
#include <sys/wait.h> /* wait() */
|
||||||
|
|
||||||
#include <string.h> /* strerror() */
|
#include <string.h> /* strerror() */
|
||||||
|
#include <unistd.h>
|
||||||
#include <libintl.h>
|
#include <libintl.h>
|
||||||
|
|
||||||
|
|
||||||
|
@ -271,16 +272,33 @@ void
|
||||||
enable_interrupt(register void (*handler) (int))
|
enable_interrupt(register void (*handler) (int))
|
||||||
{
|
{
|
||||||
if (sigivalue != SIG_IGN) {
|
if (sigivalue != SIG_IGN) {
|
||||||
|
#if defined(sun) || defined(__sun)
|
||||||
(void) bsd_signal(SIGINT, (SIG_PF) handler);
|
(void) bsd_signal(SIGINT, (SIG_PF) handler);
|
||||||
|
#else
|
||||||
|
(void) bsd_signal(SIGINT, handler);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
if (sigqvalue != SIG_IGN) {
|
if (sigqvalue != SIG_IGN) {
|
||||||
|
#if defined(sun) || defined(__sun)
|
||||||
(void) bsd_signal(SIGQUIT, (SIG_PF) handler);
|
(void) bsd_signal(SIGQUIT, (SIG_PF) handler);
|
||||||
|
#else
|
||||||
|
(void) bsd_signal(SIGQUIT, handler);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
if (sigtvalue != SIG_IGN) {
|
if (sigtvalue != SIG_IGN) {
|
||||||
|
#if defined(sun) || defined(__sun)
|
||||||
(void) bsd_signal(SIGTERM, (SIG_PF) handler);
|
(void) bsd_signal(SIGTERM, (SIG_PF) handler);
|
||||||
|
#else
|
||||||
|
(void) bsd_signal(SIGTERM, handler);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
if (sighvalue != SIG_IGN) {
|
if (sighvalue != SIG_IGN) {
|
||||||
|
#if defined(sun) || defined(__sun)
|
||||||
(void) bsd_signal(SIGHUP, (SIG_PF) handler);
|
(void) bsd_signal(SIGHUP, (SIG_PF) handler);
|
||||||
|
#else
|
||||||
|
(void) bsd_signal(SIGHUP, handler);
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,10 +36,12 @@
|
||||||
#include <errno.h> /* errno */
|
#include <errno.h> /* errno */
|
||||||
#include <libintl.h>
|
#include <libintl.h>
|
||||||
|
|
||||||
|
#if defined(sun) || defined(__sun)
|
||||||
extern char *sys_errlist[];
|
extern char *sys_errlist[];
|
||||||
extern int sys_nerr;
|
extern int sys_nerr;
|
||||||
|
#endif
|
||||||
|
|
||||||
static void file_lock_error(char *msg, char *file, char *str, int arg1, int arg2);
|
static void file_lock_error(char *msg, char *file, char *str, const char *arg1, const char *arg2);
|
||||||
|
|
||||||
#define BLOCK_INTERUPTS sigfillset(&newset) ; \
|
#define BLOCK_INTERUPTS sigfillset(&newset) ; \
|
||||||
sigprocmask(SIG_SETMASK, &newset, &oldset)
|
sigprocmask(SIG_SETMASK, &newset, &oldset)
|
||||||
|
@ -109,7 +111,7 @@ file_lock(char *name, char *lockname, int *file_locked, int timeout)
|
||||||
|
|
||||||
if (errno != EEXIST) {
|
if (errno != EEXIST) {
|
||||||
file_lock_error(msg, name, (char *)"symlink(%s, %s)",
|
file_lock_error(msg, name, (char *)"symlink(%s, %s)",
|
||||||
(int) name, (int) lockname);
|
name, lockname);
|
||||||
fprintf(stderr, "%s", msg);
|
fprintf(stderr, "%s", msg);
|
||||||
return errno;
|
return errno;
|
||||||
}
|
}
|
||||||
|
@ -157,7 +159,7 @@ file_lock(char *name, char *lockname, int *file_locked, int timeout)
|
||||||
* Format a message telling why the lock could not be created.
|
* Format a message telling why the lock could not be created.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
file_lock_error(char *msg, char *file, char *str, int arg1, int arg2)
|
file_lock_error(char *msg, char *file, char *str, const char *arg1, const char *arg2)
|
||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue