~ubuntu-dev/ubuntu/lucid/mpd/lucid-201002101854

« back to all changes in this revision

Viewing changes to src/utils.c

  • Committer: Bazaar Package Importer
  • Author(s): Charles Majola
  • Date: 2005-02-15 10:43:58 UTC
  • Revision ID: james.westby@ubuntu.com-20050215104358-w8b7yaqqfmsoxj5k
Tags: upstream-0.11.5
ImportĀ upstreamĀ versionĀ 0.11.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* the Music Player Daemon (MPD)
 
2
 * (c)2003-2004 by Warren Dukes (shank@mercury.chem.pitt.edu)
 
3
 * This project's homepage is: http://www.musicpd.org
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation; either version 2 of the License, or
 
8
 * (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, write to the Free Software
 
16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
17
 */
 
18
 
 
19
#include "utils.h"
 
20
 
 
21
#include <stdlib.h>
 
22
#include <string.h>
 
23
#include <ctype.h>
 
24
#include <sys/types.h>
 
25
#include <sys/socket.h>
 
26
#include <sys/select.h>
 
27
#include <sys/time.h>
 
28
#include <unistd.h>
 
29
 
 
30
char * myFgets(char * buffer, int bufferSize, FILE * fp) {
 
31
        char * ret = fgets(buffer,bufferSize,fp);
 
32
        if(ret && strlen(buffer)>0 && buffer[strlen(buffer)-1]=='\n') {
 
33
                buffer[strlen(buffer)-1] = '\0';
 
34
        }
 
35
        if(ret && strlen(buffer)>0 && buffer[strlen(buffer)-1]=='\r') {
 
36
                buffer[strlen(buffer)-1] = '\0';
 
37
        }
 
38
        return ret;
 
39
}
 
40
 
 
41
char * strDupToUpper(char * str) {
 
42
        char * ret = strdup(str);
 
43
        int i;
 
44
        
 
45
        for(i=0;i<strlen(str);i++) ret[i] = toupper((int)ret[i]);
 
46
        
 
47
        return ret;
 
48
}
 
49
 
 
50
void stripReturnChar(char * string) {
 
51
        while(string && (string = strstr(string,"\n"))) {
 
52
                *string = ' ';
 
53
        }
 
54
}
 
55
 
 
56
void my_usleep(long usec) {
 
57
        struct timeval tv;
 
58
 
 
59
        tv.tv_sec = 0;
 
60
        tv.tv_usec = usec;
 
61
 
 
62
        select(0,NULL,NULL,NULL,&tv);
 
63
}
 
64
 
 
65
int ipv6Supported() {
 
66
#ifdef HAVE_IPV6
 
67
        int s;
 
68
        s = socket(AF_INET6,SOCK_STREAM,0);
 
69
        if(s == -1) return 0;
 
70
        close(s);
 
71
        return 1;
 
72
#endif
 
73
        return 0;
 
74
}
 
75
 
 
76
char * appendToString(char * dest, const char * src) {
 
77
        int destlen;
 
78
        int srclen = strlen(src);
 
79
                                                                                
 
80
        if(dest == NULL) {
 
81
                dest = malloc(srclen+1);
 
82
                memset(dest, 0, srclen+1);
 
83
                destlen = 0;
 
84
        }
 
85
        else {
 
86
                destlen = strlen(dest);
 
87
                dest = realloc(dest, destlen+srclen+1);
 
88
        }
 
89
                                                                                
 
90
        memcpy(dest+destlen, src, srclen);
 
91
        dest[destlen+srclen] = '\0';
 
92
                                                                                
 
93
        return dest;
 
94
}