Prusa MINI Firmware overview
Collaboration diagram for Non-standard functions:

Functions

char * lwip_strnstr (const char *buffer, const char *token, size_t n)
 
int lwip_stricmp (const char *str1, const char *str2)
 
int lwip_strnicmp (const char *str1, const char *str2, size_t len)
 
void lwip_itoa (char *result, size_t bufsize, int number)
 

Detailed Description

lwIP provides default implementations for non-standard functions. These can be mapped to OS functions to reduce code footprint if desired. All defines related to this section must not be placed in lwipopts.h, but in arch/cc.h! These options cannot be #defined in lwipopts.h since they are not options of lwIP itself, but options of the lwIP port to your system.

Function Documentation

◆ lwip_strnstr()

char* lwip_strnstr ( const char *  buffer,
const char *  token,
size_t  n 
)

lwIP default implementation for strnstr() non-standard function. This can be #defined to strnstr() depending on your platform port.

106 {
107  const char* p;
108  size_t tokenlen = strlen(token);
109  if (tokenlen == 0) {
110  return LWIP_CONST_CAST(char *, buffer);
111  }
112  for (p = buffer; *p && (p + tokenlen <= buffer + n); p++) {
113  if ((*p == *token) && (strncmp(p, token, tokenlen) == 0)) {
114  return LWIP_CONST_CAST(char *, p);
115  }
116  }
117  return NULL;
118 }

◆ lwip_stricmp()

int lwip_stricmp ( const char *  str1,
const char *  str2 
)

lwIP default implementation for stricmp() non-standard function. This can be #defined to stricmp() depending on your platform port.

129 {
130  char c1, c2;
131 
132  do {
133  c1 = *str1++;
134  c2 = *str2++;
135  if (c1 != c2) {
136  char c1_upc = c1 | 0x20;
137  if ((c1_upc >= 'a') && (c1_upc <= 'z')) {
138  /* characters are not equal an one is in the alphabet range:
139  downcase both chars and check again */
140  char c2_upc = c2 | 0x20;
141  if (c1_upc != c2_upc) {
142  /* still not equal */
143  /* don't care for < or > */
144  return 1;
145  }
146  } else {
147  /* characters are not equal but none is in the alphabet range */
148  return 1;
149  }
150  }
151  } while (c1 != 0);
152  return 0;
153 }

◆ lwip_strnicmp()

int lwip_strnicmp ( const char *  str1,
const char *  str2,
size_t  len 
)

lwIP default implementation for strnicmp() non-standard function. This can be #defined to strnicmp() depending on your platform port.

164 {
165  char c1, c2;
166 
167  do {
168  c1 = *str1++;
169  c2 = *str2++;
170  if (c1 != c2) {
171  char c1_upc = c1 | 0x20;
172  if ((c1_upc >= 'a') && (c1_upc <= 'z')) {
173  /* characters are not equal an one is in the alphabet range:
174  downcase both chars and check again */
175  char c2_upc = c2 | 0x20;
176  if (c1_upc != c2_upc) {
177  /* still not equal */
178  /* don't care for < or > */
179  return 1;
180  }
181  } else {
182  /* characters are not equal but none is in the alphabet range */
183  return 1;
184  }
185  }
186  } while (len-- && c1 != 0);
187  return 0;
188 }

◆ lwip_itoa()

void lwip_itoa ( char *  result,
size_t  bufsize,
int  number 
)

lwIP default implementation for itoa() non-standard function. This can be #defined to itoa() or snprintf(result, bufsize, "%d", number) depending on your platform port.

199 {
200  const int base = 10;
201  char* ptr = result, *ptr1 = result, tmp_char;
202  int tmp_value;
203  LWIP_UNUSED_ARG(bufsize);
204 
205  do {
206  tmp_value = number;
207  number /= base;
208  *ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz"[35 + (tmp_value - number * base)];
209  } while(number);
210 
211  /* Apply negative sign */
212  if (tmp_value < 0) {
213  *ptr++ = '-';
214  }
215  *ptr-- = '\0';
216  while(ptr1 < ptr) {
217  tmp_char = *ptr;
218  *ptr--= *ptr1;
219  *ptr1++ = tmp_char;
220  }
221 }
NULL
#define NULL
Definition: usbd_def.h:53
LWIP_UNUSED_ARG
#define LWIP_UNUSED_ARG(x)
Definition: arch.h:308
LWIP_CONST_CAST
#define LWIP_CONST_CAST(target_type, val)
Definition: arch.h:180