/[path-sandbox]/trunk/libsbutil/src/string.c
Gentoo

Contents of /trunk/libsbutil/src/string.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 407 - (show annotations) (download) (as text)
Sun Nov 16 02:28:16 2008 UTC (5 years, 8 months ago) by vapier
File MIME type: text/x-csrc
File size: 1587 byte(s)
drop some unused code
1 /*
2 * string.c
3 *
4 * Miscellaneous macro's and functions.
5 *
6 * Copyright 1999-2008 Gentoo Foundation
7 * Copyright 2004-2007 Martin Schlemmer <azarah@nosferatu.za.org>
8 * Licensed under the GPL-2
9 */
10
11 #include "headers.h"
12 #include "rcscripts/rcutil.h"
13
14 char *
15 rc_strcatpaths (const char *pathname1, const char *pathname2)
16 {
17 char *new_path = NULL;
18 int lenght;
19
20 if ((!check_arg_str (pathname1)) || (!check_arg_str (pathname2)))
21 return 0;
22
23 /* Lenght of pathname1 + lenght of pathname2 + '/' if needed */
24 lenght = strlen (pathname1) + strlen (pathname2) + 2;
25 /* lenght + '\0' */
26 new_path = xmalloc (lenght);
27 if (NULL == new_path)
28 return NULL;
29
30 snprintf (new_path, lenght, "%s%s%s", pathname1,
31 (pathname1[strlen (pathname1) - 1] != '/') ? "/" : "",
32 pathname2);
33
34 return new_path;
35 }
36
37 char *
38 rc_strndup (const char *str, size_t size)
39 {
40 char *new_str = NULL;
41 size_t len;
42
43 /* We cannot check if its a valid string here, as it might
44 * not be '\0' terminated ... */
45 if (!check_arg_ptr (str))
46 return NULL;
47
48 /* Check lenght of str without breaching the size limit */
49 for (len = 0; (len < size) && ('\0' != str[len]); len++);
50
51 new_str = xmalloc (len + 1);
52 if (NULL == new_str)
53 return NULL;
54
55 /* Make sure our string is NULL terminated */
56 new_str[len] = '\0';
57
58 return (char *) memcpy (new_str, str, len);
59 }
60
61 char *
62 rc_basename (const char *path)
63 {
64 char *new_path = NULL;
65
66 if (!check_arg_str (path))
67 return NULL;
68
69 /* Copied from glibc */
70 new_path = strrchr (path, '/');
71 return new_path ? new_path + 1 : (char *) path;
72 }

  ViewVC Help
Powered by ViewVC 1.1.20