+ Addition of function prototypes.
+ Change function definitions to ANSI C style.
+ Initial support for CMake
+ Added support for sys_tmpdir for better portability.
--- /dev/null
+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)
+
--"./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" },
*/
/* $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;
}
#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;
}
#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;
}
*/
/* $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;
}
#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();
#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 */
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]
--- /dev/null
+/* 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 ".";
+}
+
+