Reputation: 20222
I want to make an interface to a system call handler but I don't want to declare the functions implementing it in the header file as well.
I want them to be static
, within the syscall.c
(the source file) rather than being declared in syscall..h
(the header file).
Is there any way of achieving this? Also, do you know of any C books touching upon this subject?
//container of pointers to the functions executing the system call
typedef struct
{
void (*halt) (void);
void (*exit) (int status);
pid_t (*exec) (const char *file);
int (*wait) (pid_t pid);
bool (*create) (const char *file, int initial_size);
bool (*remove) (const char *file);
int (*open) (const char *file);
int (*filesize) (int fd);
int (*read) (int fd, void *buffer, int length);
int (*write) (int fd, const void *buffer, int length);
void (*seek) (int fd, int position);
int (*tell) (int fd);
void (*close) (int fd);
}td_sys_call_handler;
//points to system call handling functions
static td_sys_call_handler syscall_redirect =
{
.halt = fu_halt,
.exit = fu_exit,
.exec = fu_exec,
.wait = process_wait,
.create = fu_create,
.remove = fu_remove,
.open = fu_open,
.filesize = fu_file_filesize,
.read = fu_read,
.write = fu_write,
.seek = fu_file_seek,
.tell = fu_file_tell,
.close = fu_file_close,
};
Upvotes: 2
Views: 66
Reputation: 34563
In the header, declare:
extern td_sys_call_handler syscall_redirect;
and in the implementation (syscall.c
), just define the structure as a normal global variable — but don't make it static
. (A static
variable has internal linkage, so it can't be referred to by other modules, but the whole point of this structure is for other modules to use it.)
Upvotes: 4