Better ANSI C compatibility and portability - part 1:

+ Addition of function prototypes.
+ Change function definitions to ANSI C style.
+ Convert to sed scripts some shell scripts for better portability.
+ Reduce usage of em_path.h
This commit is contained in:
carl 2019-02-19 00:31:58 +08:00
parent 4555c1c8cf
commit 0f75cc09ad
12 changed files with 143 additions and 159 deletions

View file

@ -0,0 +1,29 @@
cmake_minimum_required (VERSION 3.0)
project (alloc)
set(SRC
botch.c
clear.c
Malloc.c
No_Mem.c
Realloc.c
Salloc.c
Srealloc.c
std_alloc.c
st_alloc.c
alloc.h
)
add_library(${PROJECT_NAME} ${SRC})
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
set_target_properties(${PROJECT_NAME} PROPERTIES PUBLIC_HEADER "alloc.h")
install(TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
PUBLIC_HEADER DESTINATION include
)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/alloc.3 DESTINATION man OPTIONAL)

View file

@ -17,9 +17,7 @@ extern char *malloc();
#endif #endif
#include "alloc.h" #include "alloc.h"
char * char *Malloc(unsigned int sz)
Malloc(sz)
unsigned int sz;
{ {
register char *res = malloc(sz); register char *res = malloc(sz);

View file

@ -1,14 +1,15 @@
/* $Id$ */ /* $Id$ */
/* /*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright". * See the copyright notice in the ACK home directory, in the file "Copyright".
*/ */
#include <system.h> #include <stdio.h>
#include <stdlib.h>
#include "alloc.h" #include "alloc.h"
void void No_Mem(void)
No_Mem()
{ {
sys_write(STDERR, "Out of memory\n", 14); fprintf(stderr,"Out of memory\n");
sys_stop(S_EXIT); exit(1);
} }

View file

@ -19,10 +19,7 @@ extern char *realloc();
#include "alloc.h" #include "alloc.h"
char * char *Realloc(char ptr[], unsigned int sz)
Realloc(ptr, sz)
char ptr[];
unsigned int sz;
{ {
register char *mptr; register char *mptr;

View file

@ -19,10 +19,7 @@ extern char *malloc();
#include "alloc.h" #include "alloc.h"
char * char *Salloc(register char *str, register unsigned int sz)
Salloc(str, sz)
register char *str;
register unsigned int sz;
{ {
/* Salloc() is not a primitive function: it just allocates a /* Salloc() is not a primitive function: it just allocates a
piece of storage and copies a given string into it. piece of storage and copies a given string into it.

View file

@ -12,10 +12,7 @@
#include "alloc.h" #include "alloc.h"
char * char *Srealloc(char str[], unsigned int sz)
Srealloc(str, sz)
char str[];
unsigned int sz;
{ {
return Realloc(str, sz); return Realloc(str, sz);
} }

View file

@ -5,44 +5,19 @@ Malloc, Salloc, Realloc, Srealloc, st_alloc, st_free\ \-\ low level memory alloc
.SH SYNOPSIS .SH SYNOPSIS
.B #include <alloc.h> .B #include <alloc.h>
.PP .PP
.B char *Malloc(size) .B char *Malloc(unsigned int size)
.br
.B unsigned int size;
.PP .PP
.B char *Salloc(str, size) .B char *Salloc(char *str, unsigned int size)
.br
.B char *str;
.B unsigned int size;
.PP .PP
.B char *Realloc(ptr, size) .B char *Realloc(char *buf, unsigned int size)
.B char *buf;
.B unsigned int size;
.PP .PP
.B char *Srealloc(str, size) .B char *Srealloc(char *str, unsigned int size)
.br
.B char *str;
.br
.B unsigned int size;
.PP .PP
.B char *st_alloc(phead, size, count) .B char *st_alloc(char **phead, unsigned int size, int count)
.br
.B char **phead;
.br
.B unsigned int size;
.PP .PP
.B st_free(ptr, phead, size) .B st_free(char *ptr, char **phead, unsigned int size)
.br
.B char *ptr;
.br
.B char **phead;
.br
.B unsigned int size;
.PP .PP
.B void clear(ptr, size) .B void clear(char *ptr, unsigned int size)
.br
.B char *ptr;
.br
.B unsigned int size;
.PP .PP
.void No_Mem() .void No_Mem()
.PP .PP

View file

@ -9,10 +9,7 @@
#include "alloc.h" #include "alloc.h"
void void botch(register char *ptr, register unsigned int n)
botch(ptr, n)
register char *ptr;
register unsigned int n;
{ {
while (n >= sizeof (long)) { while (n >= sizeof (long)) {
/* high-speed botch loop */ /* high-speed botch loop */

View file

@ -10,10 +10,7 @@
/* instead of Calloc: */ /* instead of Calloc: */
void void clear(register char *ptr, register unsigned int n)
clear(ptr, n)
register char *ptr;
register unsigned int n;
{ {
register long *q = (long *) ptr; register long *q = (long *) ptr;

View file

@ -12,16 +12,16 @@
#include <stdlib.h> #include <stdlib.h>
#else #else
extern char *malloc(); extern char *malloc();
#ifndef NULL
#define NULL 0
#endif
#endif #endif
#include "alloc.h" #include "alloc.h"
char * char *st_alloc(char **phead, register unsigned int size, int count)
st_alloc(phead, size, count)
char **phead;
register unsigned int size;
{ {
register char *p; register char *p = NULL;
register long *q; register long *q;
char *retval; char *retval;
@ -29,7 +29,7 @@ st_alloc(phead, size, count)
while (count >= 1 && (p = malloc(size * count)) == 0) { while (count >= 1 && (p = malloc(size * count)) == 0) {
count >>= 1; count >>= 1;
} }
if (p == 0) { if (p == NULL) {
No_Mem(); No_Mem();
} }
((_PALLOC_) p)->_A_next = 0; ((_PALLOC_) p)->_A_next = 0;

View file

@ -17,11 +17,7 @@ extern char *malloc();
#include "alloc.h" #include "alloc.h"
char * char *std_alloc(char **phead, register unsigned int size, int count, int *pcnt)
std_alloc(phead, size, count, pcnt)
char **phead;
register unsigned int size;
int *pcnt;
{ {
register char *p; register char *p;
register long *q; register long *q;