source: vendor/synergy/current/lib/arch/CArchFileUnix.cpp

Last change on this file was 2749, checked in by bird, 19 years ago

synergy v1.3.1 sources (zip).

File size: 1.9 KB
Line 
1/*
2 * synergy -- mouse and keyboard sharing utility
3 * Copyright (C) 2002 Chris Schoeneman
4 *
5 * This package is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * found in the file COPYING that should have accompanied this file.
8 *
9 * This package is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14
15#include "CArchFileUnix.h"
16#include <stdio.h>
17#include <unistd.h>
18#include <pwd.h>
19#include <sys/types.h>
20#include <cstring>
21
22//
23// CArchFileUnix
24//
25
26CArchFileUnix::CArchFileUnix()
27{
28 // do nothing
29}
30
31CArchFileUnix::~CArchFileUnix()
32{
33 // do nothing
34}
35
36const char*
37CArchFileUnix::getBasename(const char* pathname)
38{
39 if (pathname == NULL) {
40 return NULL;
41 }
42
43 const char* basename = strrchr(pathname, '/');
44 if (basename != NULL) {
45 return basename + 1;
46 }
47 else {
48 return pathname;
49 }
50}
51
52std::string
53CArchFileUnix::getUserDirectory()
54{
55 char* buffer = NULL;
56 std::string dir;
57#if HAVE_GETPWUID_R
58 struct passwd pwent;
59 struct passwd* pwentp;
60#if defined(_SC_GETPW_R_SIZE_MAX)
61 long size = sysconf(_SC_GETPW_R_SIZE_MAX);
62 if (size == -1) {
63 size = BUFSIZ;
64 }
65#else
66 long size = BUFSIZ;
67#endif
68 buffer = new char[size];
69 getpwuid_r(getuid(), &pwent, buffer, size, &pwentp);
70#else
71 struct passwd* pwentp = getpwuid(getuid());
72#endif
73 if (pwentp != NULL && pwentp->pw_dir != NULL) {
74 dir = pwentp->pw_dir;
75 }
76 delete[] buffer;
77 return dir;
78}
79
80std::string
81CArchFileUnix::getSystemDirectory()
82{
83 return "/etc";
84}
85
86std::string
87CArchFileUnix::concatPath(const std::string& prefix,
88 const std::string& suffix)
89{
90 std::string path;
91 path.reserve(prefix.size() + 1 + suffix.size());
92 path += prefix;
93 if (path.size() == 0 || path[path.size() - 1] != '/') {
94 path += '/';
95 }
96 path += suffix;
97 return path;
98}
Note: See TracBrowser for help on using the repository browser.