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