summaryrefslogtreecommitdiff
path: root/librarian/rarian-utils.c
blob: b17abd70e128edbe2103d6eea0e54e12ba88da9e (plain)
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
/*
 * rarian-utils.c
 * This file is part of Rarian
 *
 * Copyright (C) 2006 - Don Scorgie
 *
 * Rarian is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * Rarian is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#ifdef HAVE_MALLOC_H
#include <malloc.h>
#endif /* HAS_MALLOC_H */
#include "rarian-utils.h"

char*
rrn_chug (char *string)
{
	char *start;

	for (start = (char*) string; *start && isspace (*start); start++)
		;

	memmove (string, start, strlen ((char *) start) + 1);

	return string;
}

char*
rrn_chomp (char        *string)
{
	int len;

	len = strlen (string);

	while (len--) {
		if (isspace ((char) string[len]))
			string[len] = '\0';
		else
			break;
	}

  return string;
}

char *
rrn_strndup (char *string, int len)
{
  char *new_str = NULL;

  if (string) {
    new_str = (char *) calloc (sizeof(char), len + 1);
      strncpy (new_str, string, len);
      new_str[len] = '\0';
  } else
    new_str = NULL;

  return new_str;
}