removed a number of gratuitous linuxisms

This commit is contained in:
Jean-Francois Dockes 2015-08-18 12:44:53 +02:00
parent 04cd868950
commit 82922bda8d
12 changed files with 66 additions and 46 deletions

View File

@ -14,6 +14,18 @@ pxattr: $(PXATTROBJS)
trpxattr.o : pxattr.cpp
$(CXX) -c $(CXXFLAGS) -DTEST_PXATTR -o $@ pxattr.cpp
PTMUTEXOBJS = ptmutex.o
ptmutex: $(PTMUTEXOBJS)
$(CXX) -o ptmutex $(PTMUTEXOBJS) $(LIBRECOLL)
ptmutex.o : ptmutex.cpp
$(CXX) -c $(CXXFLAGS) -o $@ $<
WORKQUEUEOBJS = workqueue.o
workqueue: $(WORKQUEUEOBJS)
$(CXX) -o workqueue $(WORKQUEUEOBJS) $(LIBRECOLL) -lpthread
workqueue.o : workqueue.cpp
$(CXX) -c $(CXXFLAGS) -o $@ $<
ECRONTAB_OBJS= trecrontab.o
trecrontab : $(ECRONTAB_OBJS)
$(CXX) -o trecrontab $(ECRONTAB_OBJS) $(LIBRECOLL)

View File

@ -176,7 +176,6 @@ const string& DesktopDb::getReason()
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
@ -212,8 +211,7 @@ int main(int argc, char **argv)
vector<DesktopDb::AppDef> appdefs;
DesktopDb *ddb = DesktopDb::getDb();
if (ddb == 0) {
cerr << "Could not initialize desktop db: " << DesktopDb::getReason()
<< endl;
cerr << "Could not create desktop db\n";
exit(1);
}
if (!ddb->appForMime(mime, &appdefs, &reason)) {

View File

@ -18,6 +18,8 @@
#define _APPFORMIME_H_INCLUDED_
#include <string>
#include <map>
#include <vector>
/**
* Rather strangely, I could not find a reasonably simple piece of
@ -71,12 +73,12 @@ public:
*/
bool appByName(const string& nm, AppDef& app);
typedef map<string, vector<DesktopDb::AppDef> > AppMap;
typedef std::map<std::string, std::vector<DesktopDb::AppDef> > AppMap;
private:
/** This is used by getDb() and builds a db for the standard location */
DesktopDb();
void build(const string& dir);
void build(const std::string& dir);
DesktopDb(const DesktopDb &);
DesktopDb& operator=(const DesktopDb &);

View File

@ -20,9 +20,7 @@
#include <cstring>
#include <string>
#ifndef NO_NAMESPACES
using std::string;
#endif /* NO_NAMESPACES */
#undef DEBUG_BASE64
#ifdef DEBUG_BASE64
@ -270,7 +268,6 @@ void base64_encode(const string &in, string &out)
#ifdef TEST_BASE64
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "readfile.h"
@ -358,8 +355,8 @@ int main(int argc, char **argv)
fprintf(stderr, "Decoding failed\n");
exit(1);
}
::write(1, odata.c_str(),
odata.size() * sizeof(string::value_type));
fwrite(odata.c_str(), 1,
odata.size() * sizeof(string::value_type), stdout);
exit(0);
}
}

View File

@ -21,7 +21,9 @@
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#ifndef _WIN32
#include <fcntl.h>
#endif
#ifdef INCLUDE_NEW_H
#include <new.h>
@ -41,12 +43,9 @@ using std::string;
#define freeZ(X) {if (X) {free(X);X=0;}}
#endif
#ifndef NO_NAMESPACES
using namespace std;
namespace DebugLog {
#endif // NO_NAMESPACES
bool DebugLog::isspecialname(const char *logname)
{
return !strcmp(logname, "stdout") || !strcmp(logname, "stderr");
@ -193,7 +192,7 @@ static bool fileInFiles(const string& file)
return false;
}
#ifdef _WINDOWS
#ifdef _WIN32
#include <windows.h>
static void datestring(char *d, int sz) {
SYSTEMTIME buf;
@ -390,16 +389,19 @@ DebugLog *getdbl()
}
#endif
#ifndef NO_NAMESPACES
}
#endif // NO_NAMESPACES
////////////////////////////////////////// TEST DRIVER //////////////////
#else /* TEST_DEBUGLOG */
#include <stdio.h>
#include <stdlib.h>
#ifdef _WIN32
#include <windows.h>
static inline unsigned int sleep(unsigned int s) {Sleep(s * 1000); return 0;}
#else
#include <unistd.h>
#endif
#include <string.h>
#include "debuglog.h"

View File

@ -15,7 +15,6 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef TEST_IDFILE
#include <unistd.h> // for access(2)
#include <stdlib.h>
#include <ctype.h>
#include <cstring>
@ -26,9 +25,7 @@
#include "idfile.h"
#include "debuglog.h"
#ifndef NO_NAMESPACES
using namespace std;
#endif /* NO_NAMESPACES */
// Bogus code to avoid bogus valgrind mt warnings about the
// initialization of treat_mbox_... which I can't even remember the
@ -179,7 +176,6 @@ string idFileMem(const string& data)
#include <string>
#include <iostream>
#include <unistd.h>
#include <fcntl.h>
using namespace std;

View File

@ -25,7 +25,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string>
using namespace std;

View File

@ -22,18 +22,13 @@
#include <sys/types.h>
#include <sys/stat.h>
#ifndef O_STREAMING
#define O_STREAMING 0
#endif
#include <errno.h>
#include <cstdio>
#include <cstring>
#include <string>
#ifndef NO_NAMESPACES
using std::string;
#endif /* NO_NAMESPACES */
#include "readfile.h"
#include "smallut.h"
@ -78,7 +73,7 @@ bool file_scan(const string &fn, FileScanDo* doer, string *reason)
return file_scan(fn, doer, 0, size_t(-1), reason);
}
const int RDBUFSZ = 4096;
const int RDBUFSZ = 8192;
// Note: the fstat() + reserve() (in init()) calls divide cpu usage almost by 2
// on both linux i586 and macosx (compared to just append())
// Also tried a version with mmap, but it's actually slower on the mac and not
@ -95,7 +90,7 @@ bool file_scan(const string &fn, FileScanDo* doer, off_t startoffs,
// If we have a file name, open it, else use stdin.
if (!fn.empty()) {
fd = open(fn.c_str(), O_RDONLY|O_STREAMING);
fd = open(fn.c_str(), O_RDONLY);
if (fd < 0 || fstat(fd, &st) < 0) {
catstrerror(reason, "open/stat", errno);
return false;
@ -170,7 +165,6 @@ bool file_scan(const string &fn, FileScanDo* doer, off_t startoffs,
#include <stdio.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <string>

View File

@ -22,11 +22,8 @@
#include <stdlib.h>
#include <time.h>
#include <ctype.h>
#include <unistd.h>
#include <errno.h>
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <math.h>
@ -1084,7 +1081,8 @@ void catstrerror(string *reason, const char *what, int _errno)
// normally default to the posix version.
// At worse we get no message at all here.
errbuf[0] = 0;
strerror_r(_errno, errbuf, ERRBUFSZ);
// We don't use ret, it's there to silence a cc warning
char *ret = (char *)strerror_r(_errno, errbuf, ERRBUFSZ);
reason->append(errbuf);
#endif
}

View File

@ -20,9 +20,8 @@
#include <string>
#include <iostream>
#ifndef NO_NAMESPACES
using std::string;
#endif /* NO_NAMESPACES */
#include <errno.h>
#include <iconv.h>
@ -165,7 +164,6 @@ error:
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <string>
@ -219,16 +217,16 @@ int main(int argc, char **argv)
cerr << out << endl;
exit(1);
}
int fd = open(ofilename.c_str(), O_CREAT|O_TRUNC|O_WRONLY, 0666);
if (fd < 0) {
FILE *fp = fopen(ofilename.c_str(), "wb");
if (fp == 0) {
perror("Open/create output");
exit(1);
}
if (write(fd, out.c_str(), out.length()) != (int)out.length()) {
perror("write");
if (fwrite(out.c_str(), 1, out.length(), fp) != (int)out.length()) {
perror("fwrite");
exit(1);
}
close(fd);
fclose(fp);
exit(0);
}
#endif

View File

@ -1,9 +1,33 @@
/* Copyright (C) 2014 J.F.Dockes
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// Test program for the workqueue module
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#ifdef _WIN32
#include <windows.h>
static inline unsigned int sleep(unsigned int s) {Sleep(s * 1000); return 0;}
#else
#include <unistd.h>
#endif
#include "workqueue.h"
static char *thisprog;
@ -80,9 +104,9 @@ int main(int argc, char **argv)
if (argc != 0)
Usage();
WorkQueue<Task> wq(10);
WorkQueue<Task> wq("testwq", 10);
if (!wq.start(&worker, &wq)) {
if (!wq.start(2, &worker, &wq)) {
fprintf(stderr, "Start failed\n");
exit(1);
}

View File

@ -49,7 +49,7 @@ public:
* meaning no limit. hi == -1 means that the queue is disabled.
* @param lo minimum count of tasks before worker starts. Default 1.
*/
WorkQueue(const string& name, size_t hi = 0, size_t lo = 1)
WorkQueue(const std::string& name, size_t hi = 0, size_t lo = 1)
: m_name(name), m_high(hi), m_low(lo),
m_workers_exited(0), m_clients_waiting(0), m_workers_waiting(0),
m_tottasks(0), m_nowake(0), m_workersleeps(0), m_clientsleeps(0)
@ -309,7 +309,7 @@ private:
}
// Configuration
string m_name;
std::string m_name;
size_t m_high;
size_t m_low;