• Main Page
  • Classes
  • Files
  • File List

CArchFileUnix.cpp

00001 /*
00002  * synergy -- mouse and keyboard sharing utility
00003  * Copyright (C) 2012 Bolton Software Ltd.
00004  * Copyright (C) 2002 Chris Schoeneman
00005  * 
00006  * This package is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * found in the file COPYING that should have accompanied this file.
00009  * 
00010  * This package is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017  */
00018 
00019 #include "CArchFileUnix.h"
00020 #include <stdio.h>
00021 #include <unistd.h>
00022 #include <pwd.h>
00023 #include <sys/types.h>
00024 #include <cstring>
00025 
00026 //
00027 // CArchFileUnix
00028 //
00029 
00030 CArchFileUnix::CArchFileUnix()
00031 {
00032     // do nothing
00033 }
00034 
00035 CArchFileUnix::~CArchFileUnix()
00036 {
00037     // do nothing
00038 }
00039 
00040 const char*
00041 CArchFileUnix::getBasename(const char* pathname)
00042 {
00043     if (pathname == NULL) {
00044         return NULL;
00045     }
00046 
00047     const char* basename = strrchr(pathname, '/');
00048     if (basename != NULL) {
00049         return basename + 1;
00050     }
00051     else {
00052         return pathname;
00053     }
00054 }
00055 
00056 std::string
00057 CArchFileUnix::getUserDirectory()
00058 {
00059     char* buffer = NULL;
00060     std::string dir;
00061 #if HAVE_GETPWUID_R
00062     struct passwd pwent;
00063     struct passwd* pwentp;
00064 #if defined(_SC_GETPW_R_SIZE_MAX)
00065     long size = sysconf(_SC_GETPW_R_SIZE_MAX);
00066     if (size == -1) {
00067         size = BUFSIZ;
00068     }
00069 #else
00070     long size = BUFSIZ;
00071 #endif
00072     buffer = new char[size];
00073     getpwuid_r(getuid(), &pwent, buffer, size, &pwentp);
00074 #else
00075     struct passwd* pwentp = getpwuid(getuid());
00076 #endif
00077     if (pwentp != NULL && pwentp->pw_dir != NULL) {
00078         dir = pwentp->pw_dir;
00079     }
00080     delete[] buffer;
00081     return dir;
00082 }
00083 
00084 std::string
00085 CArchFileUnix::getSystemDirectory()
00086 {
00087     return "/etc";
00088 }
00089 
00090 std::string
00091 CArchFileUnix::concatPath(const std::string& prefix,
00092                 const std::string& suffix)
00093 {
00094     std::string path;
00095     path.reserve(prefix.size() + 1 + suffix.size());
00096     path += prefix;
00097     if (path.size() == 0 || path[path.size() - 1] != '/') {
00098         path += '/';
00099     }
00100     path += suffix;
00101     return path;
00102 }

Generated on Mon May 20 2013 00:00:04 for Synergy by  doxygen 1.7.1