pelib
2.0.0
|
00001 /* 00002 * size_t.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 <math.h> 00025 #include <stdlib.h> 00026 00027 #include <pelib/size_t.h> 00028 00029 int 00030 pelib_copy(size_t)(size_t s1, size_t * s2) 00031 { 00032 *s2 = s1; 00033 00034 return 1; 00035 } 00036 00037 int 00038 pelib_init(size_t)(size_t *var) 00039 { 00040 *var = 0; 00041 00042 return 1; 00043 } 00044 00045 int 00046 pelib_compare(size_t)(size_t a, size_t b) 00047 { 00048 return a - b; 00049 } 00050 00051 char* 00052 pelib_string(size_t)(size_t a) 00053 { 00054 size_t size; 00055 char* str; 00056 00057 if(a > 0) 00058 { 00059 size = (int)log10(a); 00060 } 00061 else 00062 { 00063 size = 1; 00064 } 00065 str = malloc(sizeof(char) * (size + 2)); 00066 sprintf(str, "%zu", a); 00067 00068 return str; 00069 } 00070 00071 char* 00072 pelib_string_detail(size_t)(size_t a, int level) 00073 { 00074 return pelib_string(size_t)(a); 00075 } 00076 00077 size_t 00078 pelib_fread(size_t)(size_t* buffer, FILE* stream) 00079 { 00080 size_t total; 00081 size_t num; 00082 int 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 stack implementation 00105 #define STACK_T size_t 00106 #include <pelib/stack.c> 00107 00108 // Generic circular fifos 00109 #define CFIFO_T size_t 00110 #include <pelib/fifo.c> 00111