1 : #define VSTR_VERSION_C
2 : /*
3 : * Copyright (C) 1999, 2000, 2001, 2002, 2003 James Antill
4 : *
5 : * This library is free software; you can redistribute it and/or
6 : * modify it under the terms of the GNU Lesser General Public
7 : * License as published by the Free Software Foundation; either
8 : * version 2 of the License, or (at your option) any later version.
9 : *
10 : * This library is distributed in the hope that it will be useful,
11 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 : * Lesser General Public License for more details.
14 : *
15 : * You should have received a copy of the GNU Lesser General Public
16 : * License along with this library; if not, write to the Free Software
17 : * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 : *
19 : * email: james@and.org
20 : */
21 :
22 : /* prints the version and some info out when you run the library */
23 :
24 : #include "main.h"
25 :
26 :
27 : #ifndef USE_SYSCALL_MAIN
28 : # define USE_SYSCALL_MAIN 0 /* use for coverage, does "normal" syscalls */
29 : #endif
30 :
31 : /* syscall on Linux x86 doesn't work in a shared library as the PIC code
32 : * uses %bx. If you are compiling for static only, the this should work.
33 : * However then you can't run the library anyway.
34 : *
35 : * Code does inline asm for i386 Linux */
36 : #if (defined(HAVE_SYSCALL_H) && defined(USE_SYSCALL))
37 : #include <syscall.h>
38 :
39 : # define write(x, y, z) vstr__sys_write(x, y, z)
40 : static _syscall3(int, write, int, fd, const void *, buf, int, count)
41 : # define exit(x) vstr__sys_exit(x)
42 : static _syscall1(int, exit, int, ret)
43 : #endif
44 :
45 : void vstr_version_func(void)
46 5 : {
47 5 : int fd = 1;
48 5 : const char *const msg = "\n"
49 : "Vstr library release version -- 1.0.14 --, by James Antill.\n"
50 : "Copyright (C) 1999, 2000, 2001, 2002, 2003 James Antill.\n"
51 : "This is free software; see the source for copying conditions.\n"
52 : "There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A\n"
53 : "PARTICULAR PURPOSE.\n\n"
54 : "Built as follows:\n"
55 : " Compiled on " __DATE__ " at " __TIME__ ".\n"
56 : #ifdef __VERSION__
57 : " Compiled by CC version " __VERSION__ ".\n"
58 : #endif
59 :
60 : #ifndef NDEBUG
61 : " Debugging enabled (CFLAGS = -g -fprofile-arcs -ftest-coverage -DUSE_SYSCALL_MAIN -DUSE_RESTRICTED_HEADERS=1).\n"
62 : #else
63 : " No debugging (CFLAGS = -g -fprofile-arcs -ftest-coverage -DUSE_SYSCALL_MAIN -DUSE_RESTRICTED_HEADERS=1)\n"
64 : #endif
65 :
66 : #ifdef HAVE_POSIX_HOST
67 : " Running on a POSIX host.\n"
68 : #else
69 : " No POSIX host (iovec is manually defined, and vstr_sc_* are stubs)\n"
70 : #endif
71 :
72 : #ifdef USE_RESTRICTED_HEADERS
73 : " Compiled with restricted functionality in lib C.\n"
74 : #endif
75 :
76 : #if defined(VSTR_AUTOCONF_FMT_DBL_glibc)
77 : " Formatting floats using -- glibc -- code.\n"
78 : #elif defined(VSTR_AUTOCONF_FMT_DBL_none)
79 : " Formatting floats using -- none -- code (all floats are zero).\n"
80 : #elif defined(VSTR_AUTOCONF_FMT_DBL_host)
81 : " Formatting floats using -- host -- code.\n"
82 : #else
83 : # error "Please configure properly..."
84 : #endif
85 :
86 :
87 : " Compiler supports attributes:\n "
88 : #ifdef HAVE_ATTRIB_DEPRECATED
89 : " deprecated"
90 : #endif
91 :
92 : #ifdef HAVE_ATTRIB_MALLOC
93 : " malloc"
94 : #endif
95 :
96 : #ifdef HAVE_ATTRIB_NONNULL
97 : " nonnull"
98 : #endif
99 :
100 : #ifdef HAVE_ATTRIB_PURE
101 : " pure"
102 : #endif
103 :
104 : #ifdef HAVE_ATTRIB_PURE
105 : " const"
106 : #endif
107 :
108 : #if VSTR__USE_INTERNAL_SYMBOLS
109 : "\n Internal functions can be restricted for speed and API purity.\n"
110 : #else
111 : "\n Internal functions are exported.\n"
112 : #endif
113 :
114 : #ifdef HAVE_INLINE
115 : " Functions can be inlined for speed.\n"
116 : #else
117 : " Functions cannot be inlined.\n"
118 : #endif
119 :
120 : #ifdef HAVE_LINKER_SCRIPT
121 : " Linker script enabled.\n"
122 : #endif
123 :
124 :
125 : "\n"
126 : "Information can be found at:\t\t\t\thttp://www.and.org/vstr/"
127 : "\n"
128 : "Bug reports should be sent to:\t\t\t James Antill <james@and.org>"
129 : "\n\n"
130 5 : ;
131 :
132 5 : const char *scan = NULL;
133 5 : int len = 0;
134 :
135 : #if ((!USE_SYSCALL_MAIN) && defined(USE_SYSCALL_ASM) && \
136 : (defined(__linux__) && defined(__i386__)))
137 : /* this is sick, but works. */
138 :
139 : /* write syscall for Linux x86 */
140 : # define VSTR__SYS_WRITE(ret, fd, msg, len) \
141 : __asm__ __volatile__ ("\
142 : mov $4, %%eax\n\t\
143 : mov %1, %%ebx\n\t\
144 : mov %2, %%ecx\n\t\
145 : mov %3, %%edx\n\t\
146 : int $0x80\n\t\
147 : " : "=a"(ret) : "m"(fd), "m"(msg), "m"(len))
148 :
149 : /* SUCCESS exit syscall for Linux x86 */
150 : # define VSTR__SYS_EXIT_S() do { \
151 : __asm__ __volatile__ ("\
152 : mov $1, %%eax\n\t\
153 : mov $0, %%ebx\n\t\
154 : int $0x80\n\t\
155 : " : : ); } while (FALSE)
156 : /* FAILURE exit syscall for Linux x86 */
157 : # define VSTR__SYS_EXIT_F() do { \
158 : __asm__ __volatile__ ("\
159 : mov $1, %%eax\n\t\
160 : mov $1, %%ebx\n\t\
161 : int $0x80\n\t\
162 : " : : ); } while (FALSE)
163 :
164 : #elif (!USE_SYSCALL_MAIN) && (defined(HAVE_SYSCALL_H) && defined(USE_SYSCALL))
165 : /* syscall code for write/exit */
166 : /* See above for actual syscall implimentations */
167 :
168 : # define VSTR__SYS_WRITE(ret, fd, msg, len) ret = vstr__sys_write(fd, msg, len)
169 : # define VSTR__SYS_EXIT_S() vstr__sys_exit(EXIT_SUCCESS)
170 : # define VSTR__SYS_EXIT_F() vstr__sys_exit(EXIT_FAILURE)
171 :
172 : #else
173 : # include "main.h"
174 :
175 : /* this is obvious, well apart from the fact that it doesn't work unless
176 : * run via. ld.so */
177 : # define VSTR__SYS_WRITE(ret, fd, msg, len) ret = write(fd, msg, len)
178 : # define VSTR__SYS_EXIT_S() exit(EXIT_SUCCESS)
179 : # define VSTR__SYS_EXIT_F() exit(EXIT_FAILURE)
180 : #endif
181 :
182 5 : scan = msg;
183 4124 : while (*scan) ++scan;
184 5 : len = (scan - msg);
185 5 : scan = msg;
186 :
187 9 : while (len > 0)
188 : {
189 5 : int ret = -1;
190 :
191 5 : VSTR__SYS_WRITE(ret, fd, scan, len);
192 :
193 5 : if (ret < 0)
194 1 : VSTR__SYS_EXIT_F();
195 :
196 4 : scan += ret;
197 4 : len -= ret;
198 : }
199 :
200 4 : VSTR__SYS_EXIT_S();
201 : }
|