File: valgrind.c

package info (click to toggle)
aprx 2.9.0+dfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 2,352 kB
  • sloc: ansic: 15,809; sh: 598; makefile: 160
file content (101 lines) | stat: -rw-r--r-- 2,659 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/* **************************************************************** *
 *                                                                  *
 *  APRX -- 2nd generation APRS iGate and digi with                 *
 *          minimal requirement of esoteric facilities or           *
 *          libraries of any kind beyond UNIX system libc.          *
 *                                                                  *
 * (c) Matti Aarnio - OH2MQK,  2007-2014                            *
 *                                                                  *
 * **************************************************************** */

#ifdef _FOR_VALGRIND_
#include "aprx.h"

/*
 * High-efficiency algorithms used by libc cause terrible complaints
 * from valgrind..
 *
 * These naive single char at the time things don't go reading into
 * uninitialized areas..
 *
 */

int memcmp(const void *p1, const void *p2, size_t n) {
  const char *s1 = p1;
  const char *s2 = p2;
  for( ; n > 0 && *s1 == *s2 ; ++s1, ++s2, --n ) ;
  if (n == 0) return 0;
  return (*s1 - *s2);
}
void *memcpy(void *dest, const void *src, size_t n) {
  char *p = dest;
  const char *s = src;
  for ( ; n > 0; --n ) {
    *p++ = *s++;
  }
  return dest;
}
size_t strlen(const char *p) {
  size_t i;
  for ( i = 0; *p != 0; ++p, ++i ) ;
  return i;
}
char *strdup(const char *s) {
  int len = strlen(s)+1;
  char *p = malloc(len);
  memcpy(p, s, len);
  return p;
}
int strcmp(const char *s1, const char *s2) {
  for( ; *s1 && *s2 && *s1 == *s2 ; ++s1, ++s2 ) ;
  if (*s1 == 0 && *s2 == 0) return 0;
  if (*s1 == 0) return -1;
  if (*s2 == 0) return  1;
  return (*s1 - *s2);
}
int strncmp(const char *s1, const char *s2, size_t n) {
  for( ; n > 0 && *s1 && *s2 && *s1 == *s2 ; ++s1, ++s2, --n ) ;
  if (n == 0) return 0;
  if (*s1 == 0) return -1;
  if (*s2 == 0) return  1;
  return (*s1 - *s2);
}
char   *strcpy(char *dest, const char *src) {
  char *p = dest;
  while (*src != 0) {
    *p++ = *src++;
  }
  return dest;
}
char   *strncpy(char *dest, const char *src, size_t n) {
  char *p = dest;
  for (;*src != 0 && n > 0; --n) {
    *p++ = *src++;
  }
  return dest;
}
void   *memchr(const void *s, int c, size_t n) {
  const unsigned char *p = s;
  c &= 0xFF;
  for (p = s; n > 0; --n, ++p) {
    if (*p == c) return (void*)p;
  }
  return NULL;
}
void   *memrchr(const void *s, int c, size_t n) {
  const unsigned char *p = s;
  c &= 0xFF;
  for (p = s+n; n > 0; --n, --p) {
    if (*p == c) return (void*)p;
  }
  return NULL;
}
char  *strchr(const char *s, int c) {
  c &= 0xFF;
  for (; *s != 0; ++s) {
    if (((*s) & 0xFF) == c) return (char*)s;
  }
  return NULL;
}

#endif