home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
sa104os2.zip
/
SATHR104.ZIP
/
SATHER
/
SYSTEM
/
STR.C
< prev
next >
Wrap
Text File
|
1995-02-14
|
1KB
|
47 lines
/* C_str.c
C code for Sather 1.0 library external class C_STR */
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#ifndef __OS2__
#include <sys/file.h>
#endif
#include <fcntl.h>
/* Open a file for reading. */
int c_str_file_open(char *nm){return open(nm,O_RDONLY,0);}
/* Return the size of the file with descriptor `fd'. */
int c_str_file_size(int fd){return (int)lseek(fd,0L,2);}
/* Fill in `s' with the characters of `fd' starting at `st' and
going for `sz' chars. */
void c_str_file_in_str(int fd, char *s, int st, int sz)
{lseek(fd,st,0); read(fd,s,sz);}
/* Fill in `s' with the characters of `fd' starting at `st' and
going for `sz' chars, start at an offset of `bst' in `s'. */
void c_str_file_in_fstr(int fd, char *s, int st, int sz, int bst)
{lseek(fd,st,0); read(fd,s+bst,sz);}
/* Close the file described by descriptor `fd'. */
void c_str_file_close(int fd){close(fd);}
/* Split concatinate strings separated by '\0' into array of string in C. */
char **
c_str_create_astr (int size, char *s)
{
char **ptr;
int i;
/* ptr = (char **) malloc (sizeof (char *) * size); -- NLP */
ptr = (char **) GC_malloc(sizeof (char *) * size); /* -- NLP */
for (i = 0; (i < size) && (*s != 0); i++)
{
ptr[i] = s;
s = (char *) (s + strlen(s) + 1);
}
return ptr;
}