2
* util.cpp - miscellaneous support functions.
4
* Copyright (c) 2004 by Alastair M. Robinson
5
* Distributed under the terms of the GNU General Public License -
6
* see the file named "COPYING" for more details.
15
#include <sys/types.h>
2
* util.cpp - miscellaneous support functions.
4
* Copyright (c) 2004 by Alastair M. Robinson
5
* Distributed under the terms of the GNU General Public License -
6
* see the file named "COPYING" for more details.
16
#include <sys/types.h>
19
20
#include "support/searchpath.h"
20
21
#include "support/pathsupport.h"
22
23
using namespace std;
24
bool CheckSettingsDir(const char *dirname)
26
// const char *homedir=getenv("HOME");
25
bool CheckSettingsDir(const char *dirname)
27
// const char *homedir=getenv("HOME");
27
28
const char *homedir=get_homedir();
30
char *path=(char *)malloc(strlen(homedir)+strlen(dirname)+2);
31
sprintf(path,"%s%c%s",homedir,SEARCHPATH_SEPARATOR,dirname);
31
char *path=(char *)malloc(strlen(homedir)+strlen(dirname)+2);
32
sprintf(path,"%s%c%s",homedir,SEARCHPATH_SEPARATOR,dirname);
33
34
cerr << "Settings directory: " << path << endl;
38
cerr << "Need to create directory... " << errno << endl;
54
char *BuildAbsoluteFilename(const char *fname)
62
l=strlen(fname)+strlen(cwdbuf)+3;
63
result=(char *)malloc(l);
65
sprintf(result,"%s%c%s",cwdbuf,SEARCHPATH_SEPARATOR,fname);
39
cerr << "Need to create directory... " << errno << endl;
55
char *BuildAbsoluteFilename(const char *fname)
63
l=strlen(fname)+strlen(cwdbuf)+3;
64
result=(char *)malloc(l);
66
sprintf(result,"%s%c%s",cwdbuf,SEARCHPATH_SEPARATOR,fname);
70
71
char *SerialiseFilename(const char *fname,int serialno,int max)
104
int TestNumeric(char *str)
117
int TestHostName(char *str,char **hostname,int *port)
130
*hostname=(char *)malloc(hnl+1);
131
strncpy(*hostname,str,hnl);
132
(*hostname)[hnl-1]=0;
105
int TestNumeric(char *str)
118
int TestHostName(char *str,char **hostname,int *port)
131
*hostname=(char *)malloc(hnl+1);
132
strncpy(*hostname,str,hnl);
133
(*hostname)[hnl-1]=0;
143
bool CompareFiles(const char *fn1,const char *fn2)
149
i1.open(fn1,ios::binary);
150
i2.open(fn2,ios::binary);
152
i1.seekg(0, ios::end);
154
i1.seekg (0, ios::beg);
156
i2.seekg(0, ios::end);
158
i2.seekg (0, ios::beg);
162
buf1 = new char [l1];
163
buf2 = new char [l2];
168
for(int i=0;i<l1;++i)