File: stringutils.c

package info (click to toggle)
vbox3 0.1.7.1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 660 kB
  • ctags: 273
  • sloc: ansic: 3,454; sh: 1,831; makefile: 119; tcl: 22
file content (96 lines) | stat: -rw-r--r-- 2,017 bytes parent folder | download | duplicates (3)
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
/*
** $Id: stringutils.c,v 1.6 2001/01/14 13:50:21 pape Exp $
**
** Copyright 1996-1998 Michael 'Ghandi' Herold <michael@abadonna.mayn.de>
*/

#ifdef HAVE_CONFIG_H
#  include "../config.h"
#endif

#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#include "stringutils.h"

/************************************************************************* 
 **
 *************************************************************************/

unsigned char *xstrtoupper(unsigned char *text)
{
	int i;

	if (text)
	{
		for (i = 0; i < strlen(text); i++) text[i] = toupper(text[i]);
	}

	return(text);
}

/*************************************************************************/
/** xstrncpy():																			**/
/*************************************************************************/

void xstrncpy(unsigned char *dest, unsigned char *source, int max)
{
	strncpy(dest, source, max);
   
	dest[max] = '\0';
}

/************************************************************************* 
 **
 *************************************************************************/

void xstrncat(unsigned char *dest, unsigned char *source, int max)
{
   if ((max - strlen(dest)) > 0) strncat(dest, source, max - strlen(dest));

   dest[max] = '\0';
}






/*************************************************************************/
/** xstrtol():																				**/
/*************************************************************************/
      
long xstrtol(unsigned char *string, long number)
{
	long  back;
	char *stop;

	if (string)
	{
		back = strtol(string, &stop, 10);
		
		if (*stop == '\0') return(back);
	}

	return(number);
}

/*************************************************************************/
/** xstrtoo():																				**/
/*************************************************************************/

long xstrtoo(unsigned char *string, long number)
{
	long  back;
	char *stop;

	if (string)
	{
		back = strtol(string, &stop, 8);
		
		if (*stop == '\0') return(back);
	}

	return(number);
}