X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=ensc_fmt%2Ffmt-internal.h;fp=ensc_fmt%2Ffmt-internal.h;h=acfcdf8f0e6dfa7df48a6eaf21f135442b25b4c8;hb=8cf13bb177d92c93eb73dc8939777150536c2d00;hp=0000000000000000000000000000000000000000;hpb=6bf3f95de36c804c97716b2d0bdf10680c559044;p=util-vserver.git diff --git a/ensc_fmt/fmt-internal.h b/ensc_fmt/fmt-internal.h new file mode 100644 index 0000000..acfcdf8 --- /dev/null +++ b/ensc_fmt/fmt-internal.h @@ -0,0 +1,60 @@ +// $Id: fmt-internal.h,v 1.2 2004/08/19 13:53:54 ensc Exp $ --*- c -*-- + +// Copyright (C) 2003 Enrico Scholz +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +#ifndef H_UTIL_VSERVER_LIB_FMT_COMMON_H +#define H_UTIL_VSERVER_LIB_FMT_COMMON_H + +#define DIGITS "0123456789abcdefghijklmnopqrstuvwxyz" + +#define FMT_P__(X,Y) X ## Y +#define FMT_P_(X,Y) FMT_P__(X,Y) +#define FMT_P(X) FMT_P_(FMT_PREFIX, X) + +#define CONCAT__(x,y,z) x ## y ## z +#define CONCAT_(x,y,z) CONCAT__(x,y,z) +#define CONCAT(x,z) CONCAT_(x, FMT_BITSIZE, z) + +#define FMT_FN(BASE,SZ) \ + do { \ + register __typeof__(val) v = val; \ + register size_t l = 0; \ + \ + if (ptr==0) { \ + do { \ + ++l; \ + v /= BASE; \ + } while (v!=0); \ + } \ + else { \ + char buf[sizeof(val)*SZ]; \ + \ + do { \ + register unsigned int d = v%BASE; \ + v /= BASE; \ + ++l; \ + buf[sizeof(buf)-l] = DIGITS[d]; \ + } while (v!=0); \ + \ + memcpy(ptr, buf+sizeof(buf)-l, l); \ + } \ + \ + return l; \ + } while (0) + + +#endif // H_UTIL_VSERVER_LIB_FMT_COMMON_H