Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

CArchFileUnix.cpp

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

Generated on Fri Nov 6 00:21:13 2009 for synergy-plus by  doxygen 1.3.9.1