source: soft/giet_vm/giet_libs/stdlib.c @ 370

Last change on this file since 370 was 352, checked in by alain, 10 years ago

Avoid GCC warnings for some missing initialisations.

File size: 2.3 KB
Line 
1//////////////////////////////////////////////////////////////////////////////////
2// File     : stdlib.c
3// Date     : 05/12/2013
4// Author   : Clément DEVIGNE
5// Copyright (c) UPMC-LIP6
6///////////////////////////////////////////////////////////////////////////////////
7
8#include <stdlib.h>
9
10///////////////////////////////////////////////////////////////////////////////////
11// int atoi ( char * str )
12///////////////////////////////////////////////////////////////////////////////////
13       
14int atoi(char *str)
15{
16    int res  = 0; // Initialize result
17    int sign = 1; // Initialize sign as positive
18    int i    = 0; // Initialize index of first digit
19
20    if (str[0] == '-') //If number is negative, then update sign
21    {
22        sign = -1; 
23        i++;           // Also update index of first digit
24    }
25
26    for (; str[i] != '\0'; ++i) // Iterate through all digits and update the result
27    {
28        res = res*10 + str[i] - '0';
29    }
30
31    // Return result with sign
32    return sign*res;
33}
34       
35////////////////////////////////////////////////////////////////////////////////////////
36//  mempcy()
37// GCC requires this function. Taken from MutekH.
38////////////////////////////////////////////////////////////////////////////////////////
39void * memcpy(void *_dst, const void * _src, unsigned int size) 
40{
41    unsigned int * dst = _dst;
42    const unsigned int * src = _src;
43    if (!((unsigned int) dst & 3) && !((unsigned int) src & 3) )
44    {
45        while (size > 3) 
46        {
47            *dst++ = *src++;
48            size -= 4;
49        }
50    }
51
52    unsigned char *cdst = (unsigned char*)dst;
53    unsigned char *csrc = (unsigned char*)src;
54
55    while (size--) 
56    {
57        *cdst++ = *csrc++;
58    }
59    return _dst;
60}
61
62
63////////////////////////////////////////////////////////////////////////////////////////
64//  memset()
65// GCC requires this function. Taken from MutekH.
66////////////////////////////////////////////////////////////////////////////////////////
67inline void * memset(void * dst, int s, unsigned int count) 
68{
69    char * a = (char *) dst;
70    while (count--)
71    {
72        *a++ = (char)s;
73    }
74    return dst;
75}
76
77// Local Variables:
78// tab-width: 4
79// c-basic-offset: 4
80// c-file-offsets:((innamespace . 0)(inline-open . 0))
81// indent-tabs-mode: nil
82// End:
83// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
Note: See TracBrowser for help on using the repository browser.