File: utils.c

package info (click to toggle)
efingerd 1.3
  • links: PTS
  • area: main
  • in suites: potato
  • size: 180 kB
  • ctags: 36
  • sloc: sh: 297; ansic: 278; makefile: 62
file content (35 lines) | stat: -rw-r--r-- 584 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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>

#ifdef DONT_HAVE_SNPRINTF

int snprintf(char * str,int maxlen,const char * format,...)
{
  va_list ap;
  int len;
  char * ptr;
  int count=0;

  ptr=strdup(format);
  va_start(ap,format);
  do {
    ptr=strchr(ptr,'%');
    if (ptr!=NULL) {
      ptr++;
      count++;
    }
  } while(ptr);
  if (count==1) {
    sprintf(str,format,va_arg(ap,char *));
  }
  else if (count==2) {
    sprintf(str,format,va_arg(ap,char *),va_arg(ap,char *));
  }
  va_end(ap);
  *(str+maxlen)='\0';
  free(ptr);
}

#endif