mescc: Support gcc-3.2: Add getpid, signal.
* lib/linux+gnu.c (getpid, signal): New function. * include/signal.h: Declare signal. * include/unistd.h: Declare getpid. * scaffold/tests/95-signal.c: Test it. * build-aux/check-mescc.sh (tests): Run it.
This commit is contained in:
parent
7c4a6a88ed
commit
04302b3fe4
|
@ -139,6 +139,7 @@ t
|
|||
92-stat
|
||||
93-fread-fwrite
|
||||
94-unsetenv
|
||||
95-signal
|
||||
"
|
||||
|
||||
# 90: needs GNU, fails for mescc, passes for tcc
|
||||
|
|
|
@ -132,22 +132,25 @@ typedef struct siginfo_t {
|
|||
} siginfo_t;
|
||||
|
||||
|
||||
// typedef void __signalfn_t(int);
|
||||
// typedef __signalfn_t *__sighandler_t;
|
||||
// typedef __signalfn_t *__sighandler_t;
|
||||
typedef void __sighandler_t(int);
|
||||
typedef void (*sighandler_t)(int);
|
||||
|
||||
struct sigaction {
|
||||
void (*sa_sigaction) (int, siginfo_t *, void *);
|
||||
//__sighandler_t sa_handler;
|
||||
union {
|
||||
void (*sa_sigaction) (int signum, siginfo_t *, void *);
|
||||
#if __MESC__
|
||||
void (*sa_handler) (int);
|
||||
#else
|
||||
sighandler_t sa_handler;
|
||||
#endif
|
||||
};
|
||||
unsigned long sa_flags;
|
||||
sigset_t sa_mask;
|
||||
};
|
||||
|
||||
#define SIG_DFL ((__sighandler_t)0) /* default signal handling */
|
||||
#define SIG_IGN ((__sighandler_t)1) /* ignore signal */
|
||||
#define SIG_ERR ((__sighandler_t)-1) /* error return from signal */
|
||||
|
||||
#define SIG_DFL ((sighandler_t)0)
|
||||
#define SIG_IGN ((sighandler_t)1)
|
||||
#define SIG_ERR ((sighandler_t)-1)
|
||||
|
||||
#ifdef __i386__
|
||||
|
||||
|
@ -224,7 +227,13 @@ typedef struct ucontext
|
|||
} ucontext_t;
|
||||
#endif // !__i386__
|
||||
|
||||
int kill (pid_t pid, int signum);
|
||||
int sigaction (int signum, struct sigaction const *act, struct sigaction *oldact);
|
||||
#if __MESC__
|
||||
void* signal (int signum, void * action);
|
||||
#else
|
||||
sighandler_t signal (int signum, sighandler_t action);
|
||||
#endif
|
||||
int sigemptyset (sigset_t *set);
|
||||
|
||||
#endif //! WITH_GLIBC
|
||||
|
|
|
@ -59,6 +59,7 @@ int chmod (char const *file_name, mode_t mode);
|
|||
int mkdir (char const *file_name, mode_t mode);
|
||||
int chown (char const *file_name, uid_t owner, gid_t group);
|
||||
int rmdir (char const *file_name);
|
||||
int stat (char const *file_name, struct stat *buf);
|
||||
|
||||
#define S_IFCHR 0020000
|
||||
#define S_IFDIR 0040000
|
||||
|
|
|
@ -39,6 +39,12 @@
|
|||
#define STDERR_FILENO 2
|
||||
#endif // STDIN_FILENO
|
||||
|
||||
#ifndef STDIN_FILE_NO
|
||||
#define STDIN_FILE_NO 0
|
||||
#define STDOUT_FILE_NO 1
|
||||
#define STDERR_FILE_NO 2
|
||||
#endif // STDIN_FILE_NO
|
||||
|
||||
#ifndef __MES_OFF_T
|
||||
#define __MES_OFF_T
|
||||
#undef off_t
|
||||
|
@ -69,6 +75,12 @@ typedef long intptr_t;
|
|||
typedef long ptrdiff_t;
|
||||
#endif
|
||||
|
||||
#ifndef __MES_PID_T
|
||||
#define __MES_PID_T
|
||||
#undef pid_t
|
||||
typedef int pid_t;
|
||||
#endif
|
||||
|
||||
#ifndef R_OK
|
||||
#define F_OK 0
|
||||
#define X_OK 1
|
||||
|
@ -98,6 +110,8 @@ void * sbrk (intptr_t delta);
|
|||
#endif
|
||||
int unlink (char const *file_name);
|
||||
ssize_t write (int filedes, void const *buffer, size_t size);
|
||||
pid_t getpid (void);
|
||||
|
||||
#endif // ! WITH_GLIBC
|
||||
|
||||
#endif // __MES_UNISTD_H
|
||||
|
|
|
@ -98,13 +98,6 @@ getgid (int x)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
getpid (int x)
|
||||
{
|
||||
eputs ("getpid stub\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
getuid (int x)
|
||||
{
|
||||
|
|
|
@ -19,11 +19,13 @@
|
|||
*/
|
||||
|
||||
#define SYS_link 0x09
|
||||
#define SYS_getpid 0x14
|
||||
#define SYS_kill 0x25
|
||||
#define SYS_rename 0x26
|
||||
#define SYS_mkdir 0x27
|
||||
#define SYS_dup 0x29
|
||||
#define SYS_pipe 0x2a
|
||||
#define SYS_signal 0x30
|
||||
#define SYS_lstat 0x6b
|
||||
#define SYS_fstat 0x6c
|
||||
#define SYS_nanosleep 0xa2
|
||||
|
@ -34,6 +36,12 @@ link (char const *old_name, char const *new_name)
|
|||
return _sys_call2 (SYS_link, (int)old_name, (int)new_name);
|
||||
}
|
||||
|
||||
pid_t
|
||||
getpid ()
|
||||
{
|
||||
return _sys_call (SYS_getpid);
|
||||
}
|
||||
|
||||
int
|
||||
kill (pid_t pid, int signum)
|
||||
{
|
||||
|
@ -58,6 +66,17 @@ dup (int old)
|
|||
return _sys_call1 (SYS_dup, (int)old);
|
||||
}
|
||||
|
||||
#if __MESC__
|
||||
void *
|
||||
signal (int signum, void * action)
|
||||
#else
|
||||
sighandler_t
|
||||
signal (int signum, sighandler_t action)
|
||||
#endif
|
||||
{
|
||||
return _sys_call2 (SYS_signal, signum, action);
|
||||
}
|
||||
|
||||
int
|
||||
pipe (int filedes[2])
|
||||
{
|
||||
|
|
7
lib/m4.c
7
lib/m4.c
|
@ -160,13 +160,6 @@ setbuf (int x)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
signal (int x)
|
||||
{
|
||||
eputs ("signal stub\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
system (int x)
|
||||
{
|
||||
|
|
46
scaffold/tests/95-signal.c
Normal file
46
scaffold/tests/95-signal.c
Normal file
|
@ -0,0 +1,46 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* This file is part of Mes.
|
||||
*
|
||||
* Mes is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* Mes is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <libmes.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
int g_alarm_handled_p = 0;
|
||||
|
||||
void
|
||||
handler (int signum)
|
||||
{
|
||||
eputs ("handle:"); eputs (itoa (signum)); eputs ("\n");
|
||||
if (signum != SIGALRM)
|
||||
exit (1);
|
||||
g_alarm_handled_p = 1;
|
||||
}
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
signal (SIGALRM, handler);
|
||||
kill (getpid (), SIGALRM);
|
||||
if (!g_alarm_handled_p)
|
||||
return 2;
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue