1afc2ba1dSToomas Soome /*
2afc2ba1dSToomas Soome  * This file and its contents are supplied under the terms of the
3afc2ba1dSToomas Soome  * Common Development and Distribution License ("CDDL"), version 1.0.
4afc2ba1dSToomas Soome  * You may only use this file in accordance with the terms of version
5afc2ba1dSToomas Soome  * 1.0 of the CDDL.
6afc2ba1dSToomas Soome  *
7afc2ba1dSToomas Soome  * A full copy of the text of the CDDL should have accompanied this
8afc2ba1dSToomas Soome  * source.  A copy of the CDDL is also available via the Internet at
9afc2ba1dSToomas Soome  * http://www.illumos.org/license/CDDL.
10afc2ba1dSToomas Soome  */
11afc2ba1dSToomas Soome 
12afc2ba1dSToomas Soome /*
13afc2ba1dSToomas Soome  * Copyright 2015 Toomas Soome <tsoome@me.com>
14afc2ba1dSToomas Soome  */
15afc2ba1dSToomas Soome 
16afc2ba1dSToomas Soome #include "ficl.h"
17afc2ba1dSToomas Soome 
18afc2ba1dSToomas Soome void *
ficlMalloc(size_t size)19afc2ba1dSToomas Soome ficlMalloc(size_t size)
20afc2ba1dSToomas Soome {
21afc2ba1dSToomas Soome 	return (malloc(size));
22afc2ba1dSToomas Soome }
23afc2ba1dSToomas Soome 
24afc2ba1dSToomas Soome void *
ficlRealloc(void * p,size_t size)25afc2ba1dSToomas Soome ficlRealloc(void *p, size_t size)
26afc2ba1dSToomas Soome {
27afc2ba1dSToomas Soome 	return (realloc(p, size));
28afc2ba1dSToomas Soome }
29afc2ba1dSToomas Soome 
30afc2ba1dSToomas Soome void
ficlFree(void * p)31afc2ba1dSToomas Soome ficlFree(void *p)
32afc2ba1dSToomas Soome {
33afc2ba1dSToomas Soome 	free(p);
34afc2ba1dSToomas Soome }
35afc2ba1dSToomas Soome 
36afc2ba1dSToomas Soome void
ficlCallbackDefaultTextOut(ficlCallback * callback,char * message)37afc2ba1dSToomas Soome ficlCallbackDefaultTextOut(ficlCallback *callback, char *message)
38afc2ba1dSToomas Soome {
39afc2ba1dSToomas Soome 	FICL_IGNORE(callback);
40afc2ba1dSToomas Soome 
41afc2ba1dSToomas Soome 	if (message != NULL) {
42*68d77045SToomas Soome #ifdef _STANDALONE
43afc2ba1dSToomas Soome 		while (*message != 0)
44afc2ba1dSToomas Soome 			putchar((unsigned char)*(message++));
45afc2ba1dSToomas Soome #else
46afc2ba1dSToomas Soome 		(void) fputs(message, stdout);
47afc2ba1dSToomas Soome 		(void) fflush(stdout);
48afc2ba1dSToomas Soome #endif
49afc2ba1dSToomas Soome 	}
50afc2ba1dSToomas Soome }
51afc2ba1dSToomas Soome 
52afc2ba1dSToomas Soome #if FICL_WANT_FILE
53afc2ba1dSToomas Soome int
ficlFileTruncate(ficlFile * ff,ficlUnsigned size)54afc2ba1dSToomas Soome ficlFileTruncate(ficlFile *ff, ficlUnsigned size)
55afc2ba1dSToomas Soome {
56afc2ba1dSToomas Soome 	return (ftruncate(fileno(ff->f), size));
57afc2ba1dSToomas Soome }
58afc2ba1dSToomas Soome 
59afc2ba1dSToomas Soome int
ficlFileStatus(char * filename,int * status)60afc2ba1dSToomas Soome ficlFileStatus(char *filename, int *status)
61afc2ba1dSToomas Soome {
62afc2ba1dSToomas Soome 	struct stat statbuf;
63afc2ba1dSToomas Soome 
64afc2ba1dSToomas Soome 	if (stat(filename, &statbuf) == 0) {
65afc2ba1dSToomas Soome 		*status = statbuf.st_mode;
66afc2ba1dSToomas Soome 		return (0);
67afc2ba1dSToomas Soome 	}
68afc2ba1dSToomas Soome 	*status = ENOENT;
69afc2ba1dSToomas Soome 	return (-1);
70afc2ba1dSToomas Soome }
71afc2ba1dSToomas Soome 
72afc2ba1dSToomas Soome long
ficlFileSize(ficlFile * ff)73afc2ba1dSToomas Soome ficlFileSize(ficlFile *ff)
74afc2ba1dSToomas Soome {
75afc2ba1dSToomas Soome 	struct stat statbuf;
76afc2ba1dSToomas Soome 
77afc2ba1dSToomas Soome 	if (ff == NULL)
78afc2ba1dSToomas Soome 		return (-1);
79afc2ba1dSToomas Soome 
80afc2ba1dSToomas Soome 	statbuf.st_size = -1;
81afc2ba1dSToomas Soome 	if (fstat(fileno(ff->f), &statbuf) != 0)
82afc2ba1dSToomas Soome 		return (-1);
83afc2ba1dSToomas Soome 
84afc2ba1dSToomas Soome 	return (statbuf.st_size);
85afc2ba1dSToomas Soome }
86afc2ba1dSToomas Soome #endif
87