Better ANSI C compatibility and portability - part 1:
+ Addition of function prototypes. + Change function definitions to ANSI C style. + Initial support for CMake + Added support for sys_tmpdir for better portability.
This commit is contained in:
parent
7317ae3291
commit
b4df26e79d
36
modules/src/system/CMakeLists.txt
Normal file
36
modules/src/system/CMakeLists.txt
Normal file
|
@ -0,0 +1,36 @@
|
|||
cmake_minimum_required (VERSION 2.9)
|
||||
project(system)
|
||||
|
||||
set(SRC
|
||||
access.c
|
||||
break.c
|
||||
chmode.c
|
||||
close.c
|
||||
create.c
|
||||
filesize.c
|
||||
lock.c
|
||||
modtime.c
|
||||
open.c
|
||||
read.c
|
||||
remove.c
|
||||
rename.c
|
||||
seek.c
|
||||
stop.c
|
||||
system.c
|
||||
write.c
|
||||
tmpdir.c
|
||||
system.h
|
||||
)
|
||||
|
||||
add_library(${PROJECT_NAME} ${SRC})
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES PUBLIC_HEADER "system.h")
|
||||
|
||||
install(TARGETS ${PROJECT_NAME}
|
||||
RUNTIME DESTINATION bin
|
||||
LIBRARY DESTINATION lib
|
||||
ARCHIVE DESTINATION lib
|
||||
PUBLIC_HEADER DESTINATION include
|
||||
)
|
||||
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/system.3 DESTINATION man OPTIONAL)
|
||||
|
|
@ -6,7 +6,7 @@ clibrary {
|
|||
--"./lock.c",
|
||||
"./modtime.c", "./open.c", "./read.c", "./remove.c",
|
||||
"./rename.c", "./seek.c", "./stop.c", "./system.c",
|
||||
--"./unlock.c",
|
||||
--"./unlock.c”,”./tmpdir.c”,
|
||||
"./write.c",
|
||||
},
|
||||
hdrs = { "./system.h" },
|
||||
|
|
|
@ -4,12 +4,10 @@
|
|||
*/
|
||||
/* $Id$ */
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include "system.h"
|
||||
|
||||
int
|
||||
sys_chmode(path, mode)
|
||||
char *path;
|
||||
int mode;
|
||||
int sys_chmode(char* path,int mode)
|
||||
{
|
||||
return chmod(path, mode) == 0;
|
||||
return chmod(path, (mode_t)mode) == 0;
|
||||
}
|
||||
|
|
|
@ -8,13 +8,11 @@
|
|||
#include <sys/stat.h>
|
||||
#include "system.h"
|
||||
|
||||
long
|
||||
sys_filesize(path)
|
||||
char *path;
|
||||
off_t sys_filesize(char* path)
|
||||
{
|
||||
struct stat st_buf;
|
||||
|
||||
if (stat(path, &st_buf) != 0)
|
||||
return -1L;
|
||||
return (long) st_buf.st_size;
|
||||
return st_buf.st_size;
|
||||
}
|
||||
|
|
|
@ -8,13 +8,11 @@
|
|||
#include <sys/stat.h>
|
||||
#include "system.h"
|
||||
|
||||
long
|
||||
sys_modtime(path)
|
||||
char *path;
|
||||
time_t sys_modtime(char* path)
|
||||
{
|
||||
struct stat st_buf;
|
||||
|
||||
if (stat(path, &st_buf) != 0)
|
||||
return -1L;
|
||||
return (long) st_buf.st_mtime;
|
||||
return st_buf.st_mtime;
|
||||
}
|
||||
|
|
|
@ -4,11 +4,10 @@
|
|||
*/
|
||||
/* $Id$ */
|
||||
|
||||
#include <stdio.h>
|
||||
#include "system.h"
|
||||
|
||||
int
|
||||
sys_remove(path)
|
||||
char *path;
|
||||
int sys_remove(char* path)
|
||||
{
|
||||
return unlink(path) == 0;
|
||||
return remove(path) == 0;
|
||||
}
|
||||
|
|
|
@ -7,15 +7,13 @@
|
|||
#include <stdlib.h>
|
||||
#include "system.h"
|
||||
|
||||
void
|
||||
sys_stop(how)
|
||||
int how;
|
||||
void sys_stop(int how)
|
||||
{
|
||||
switch(how) {
|
||||
case S_END:
|
||||
exit(0);
|
||||
exit(EXIT_SUCCESS);
|
||||
case S_EXIT:
|
||||
exit(1);
|
||||
exit(EXIT_FAILURE);
|
||||
case S_ABORT:
|
||||
default:
|
||||
abort();
|
||||
|
|
|
@ -6,6 +6,10 @@
|
|||
#ifndef __SYSTEM_INCLUDED__
|
||||
#define __SYSTEM_INCLUDED__
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
struct _sys_fildes {
|
||||
int o_fd; /* UNIX filedescriptor */
|
||||
int o_flags; /* flags for open; 0 if not used */
|
||||
|
@ -40,15 +44,17 @@ int sys_reset(File *);
|
|||
int sys_access(char *, int);
|
||||
int sys_remove(char *);
|
||||
int sys_rename(char *, char *);
|
||||
long sys_filesize(char *);
|
||||
off_t sys_filesize(char *);
|
||||
int sys_chmode(char *, int);
|
||||
/* Return the temporary directory location */
|
||||
char* sys_gettmpdir(void);
|
||||
#if 0
|
||||
int sys_lock(char *);
|
||||
int sys_unlock(char *);
|
||||
#endif
|
||||
char *sys_break(int);
|
||||
void sys_stop(int);
|
||||
long sys_modtime(char *);
|
||||
time_t sys_modtime(char *);
|
||||
|
||||
/* standard file decsriptors */
|
||||
#define STDIN &_sys_ftab[0]
|
||||
|
|
27
modules/src/system/tmpdir.c
Normal file
27
modules/src/system/tmpdir.c
Normal file
|
@ -0,0 +1,27 @@
|
|||
/* Copyright (c) 2019. See the file "Copyright" in
|
||||
* the root directory for more information.
|
||||
*
|
||||
* Created on: 2019-02-09
|
||||
*
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
|
||||
char* sys_gettmpdir(void)
|
||||
{
|
||||
char* result = 0;
|
||||
/* Check the UNIX temporary directory */
|
||||
result = getenv("TMPDIR");
|
||||
if (result != 0)
|
||||
return result;
|
||||
result = getenv("TMP");
|
||||
if (result != 0)
|
||||
return result;
|
||||
/* DOS compatible systems */
|
||||
result = getenv("TEMP");
|
||||
if (result != 0)
|
||||
return result;
|
||||
/* Then try current directory */
|
||||
return ".";
|
||||
}
|
||||
|
||||
|
Loading…
Reference in a new issue