Switch to unified view

a/src/utils/smallut.cpp b/src/utils/smallut.cpp
1
#ifndef lint
1
#ifndef lint
2
static char rcsid[] = "@(#$Id: smallut.cpp,v 1.21 2006-12-11 14:50:53 dockes Exp $ (C) 2004 J.F.Dockes";
2
static char rcsid[] = "@(#$Id: smallut.cpp,v 1.22 2006-12-14 13:53:43 dockes Exp $ (C) 2004 J.F.Dockes";
3
#endif
3
#endif
4
/*
4
/*
5
 *   This program is free software; you can redistribute it and/or modify
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
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
7
 *   the Free Software Foundation; either version 2 of the License, or
...
...
29
#include <sys/stat.h>
29
#include <sys/stat.h>
30
30
31
#include <string>
31
#include <string>
32
32
33
#include "smallut.h"
33
#include "smallut.h"
34
#include "debuglog.h"
35
#include "pathut.h"
36
34
37
#ifndef NO_NAMESPACES
35
#ifndef NO_NAMESPACES
38
using namespace std;
36
using namespace std;
39
#endif /* NO_NAMESPACES */
37
#endif /* NO_NAMESPACES */
40
38
41
#define MIN(A,B) ((A)<(B)?(A):(B))
39
#define MIN(A,B) ((A)<(B)?(A):(B))
42
43
bool maketmpdir(string& tdir)
44
{
45
    const char *tmpdir = getenv("RECOLL_TMPDIR");
46
    if (!tmpdir)
47
  tmpdir = getenv("TMPDIR");
48
    if (!tmpdir)
49
  tmpdir = "/tmp";
50
    tdir = path_cat(tmpdir, "rcltmpXXXXXX");
51
52
    {
53
  char *cp = strdup(tdir.c_str());
54
  if (!cp) {
55
      LOGERR(("maketmpdir: out of memory (for file name !)\n"));
56
      tdir.erase();
57
      return false;
58
  }
59
#ifdef HAVE_MKDTEMP
60
  if (!mkdtemp(cp)) {
61
#else
62
  if (!mktemp(cp)) {
63
#endif // HAVE_MKDTEMP
64
      free(cp);
65
      LOGERR(("maketmpdir: mktemp failed\n"));
66
      tdir.erase();
67
      return false;
68
  }   
69
  tdir = cp;
70
  free(cp);
71
    }
72
#ifndef HAVE_MKDTEMP
73
    if (mkdir(tdir.c_str(), 0700) < 0) {
74
  LOGERR(("maketmpdir: mkdir %s failed\n", tdir.c_str()));
75
  tdir.erase();
76
  return false;
77
    }
78
#endif
79
    return true;
80
}
81
40
82
string stringlistdisp(const list<string>& sl)
41
string stringlistdisp(const list<string>& sl)
83
{
42
{
84
    string s;
43
    string s;
85
    for (list<string>::const_iterator it = sl.begin(); it!= sl.end(); it++)
44
    for (list<string>::const_iterator it = sl.begin(); it!= sl.end(); it++)
86
    s += "[" + *it + "] ";
45
    s += "[" + *it + "] ";
87
    if (!s.empty())
46
    if (!s.empty())
88
    s.erase(s.length()-1);
47
    s.erase(s.length()-1);
89
    return s;
48
    return s;
90
}
49
}
91
      
92
50
93
int stringicmp(const string & s1, const string& s2) 
51
int stringicmp(const string & s1, const string& s2) 
94
{
52
{
95
    string::const_iterator it1 = s1.begin();
53
    string::const_iterator it1 = s1.begin();
96
    string::const_iterator it2 = s2.begin();
54
    string::const_iterator it2 = s2.begin();