libwreport  2.14
fast.h
Go to the documentation of this file.
1 /*
2  * DB-ALLe - Archive for punctual meteorological data
3  *
4  * Copyright (C) 2005,2006 ARPA-SIM <urpsim@smr.arpa.emr.it>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License.
9  *
10  * This program 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
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * Author: Enrico Zini <enrico@enricozini.com>
20  */
21 
22 #ifndef DBA_CORE_FAST_H
23 #define DBA_CORE_FAST_H
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
34 #include <stdlib.h>
35 
50 static inline char *itoa(long value, int len)
51 {
52  /* Adaptation from the _itoa_word function in glibc */
53  static const char *digits = "0123456789";
54  static char buf[20] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
55  char* buflim = buf+19;
56  int negative = value < 0;
57  // if (negative) value = -value;
58  do
59  *--buflim = digits[abs(value % 10)];
60  while ((value /= 10) != 0 && --len != 0);
61  if (negative && len)
62  *--buflim = '-';
63  return buflim;
64 }
65 
66 #ifdef __cplusplus
67 }
68 #endif
69 
70 #endif
71 /* vim:set ts=4 sw=4: */