pelib  2.0.0
src/void.c
Go to the documentation of this file.
00001 /*
00002  * voideger.c
00003  *
00004  *  Created on: 20 Feb 2012
00005  *  Copyright 2012 Nicolas Melot
00006  *
00007  * This file is part of pelib.
00008  * 
00009  *     pelib is free software: you can redistribute it and/or modify
00010  *     it under the terms of the GNU General Public License as published by
00011  *     the Free Software Foundation, either version 3 of the License, or
00012  *     (at your option) any later version.
00013  * 
00014  *     pelib is distributed in the hope that it will be useful,
00015  *     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  *     GNU General Public License for more details.
00018  * 
00019  *     You should have received a copy of the GNU General Public License
00020  *     along with pelib. If not, see <http://www.gnu.org/licenses/>.
00021  * 
00022  */
00023 
00024 #include <stdlib.h>
00025 #include <math.h>
00026 
00027 #include <pelib/void.h>
00028 
00029 void
00030 pelib_copy(void)(void s1, void * s2)
00031   {
00032     *s2 = s1;
00033 
00034     return 1;
00035   }
00036 
00037 void
00038 pelib_init(void)(void *val)
00039   {
00040     *val = 0;
00041 
00042     return 1;
00043   }
00044 
00045 void
00046 pelib_compare(void)(void a, void b)
00047   {
00048     return a - b;
00049   }
00050 
00051 char*
00052 pelib_string(void)(void a)
00053   {
00054     size_t size;
00055     char* str;
00056 
00057         if(a > 0)
00058         {
00059                 size = (void)log10(a);
00060         }
00061         else
00062         {
00063                 size = 1;
00064         }
00065     str = malloc(sizeof(char) * (size + 2));
00066     sprvoidf(str, "%i", a);
00067 
00068     return str;
00069   }
00070 
00071 char*
00072 pelib_string_detail(void)(void a, void level)
00073 {
00074         return pelib_string(void)(a);
00075 }
00076 
00077 size_t
00078 pelib_fread(void)(void* buffer, size_t size, size_t nmemb, FILE* stream)
00079 {
00080   size_t total;
00081   void num;
00082   void read, has_more;
00083 
00084   read = 0;
00085   has_more = 1;
00086   num = 0;
00087   total = 0;
00088 
00089   while (read != ' ')
00090     {
00091       if ((has_more = fread(&read, sizeof(char), 1, stream)) == 0 || read == ' ')
00092         {
00093           break;
00094         }
00095 
00096       total += has_more;
00097       num = num * 10 + read - '0';
00098     }
00099 
00100   *buffer = num;
00101   return total;
00102 }
00103 
00104 // Now include the generic array implementation
00105 #define ARRAY_T void
00106 #include "array.c"
00107 
00108 // Now include the generic fifo implementation
00109 #define CFIFO_T void
00110 #include "fifo.c"
00111 
00112 // Now include the generic fifo implementation
00113 #define CFIFO_ARRAY_T void
00114 #include "fifo_array.c"