blob: 657edda3f4aae6a5fcd12493a08d1596086237b3 [file] [log] [blame]
sgk@google.come1f4a242009-04-22 02:20:10 +09001// Copyright (c) 2009 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef BASE_LINUX_UTIL_H__
6#define BASE_LINUX_UTIL_H__
7
8#include <stdint.h>
craig.schlenter@chromium.orgfd4599a2009-10-30 03:21:30 +09009#include <sys/types.h>
sgk@google.come1f4a242009-04-22 02:20:10 +090010
thestig@chromium.orga5a2b6e2009-07-17 14:55:51 +090011#include <string>
12
sgk@google.come1f4a242009-04-22 02:20:10 +090013namespace base {
14
15// Makes a copy of |pixels| with the ordering changed from BGRA to RGBA.
16// The caller is responsible for free()ing the data. If |stride| is 0,
17// it's assumed to be 4 * |width|.
18uint8_t* BGRAToRGBA(const uint8_t* pixels, int width, int height, int stride);
19
thestig@chromium.orga5a2b6e2009-07-17 14:55:51 +090020// Get the Linux Distro if we can, or return "Unknown", similar to
21// GetWinVersion() in base/win_util.h.
22std::string GetLinuxDistro();
23
mattm@chromium.org625865e2009-07-22 09:22:49 +090024// These are used to derive mocks for unittests.
25class EnvironmentVariableGetter {
26 public:
27 virtual ~EnvironmentVariableGetter() {}
28 // Gets an environment variable's value and stores it in
29 // result. Returns false if the key is unset.
30 virtual bool Getenv(const char* variable_name, std::string* result) = 0;
31
32 // Create an instance of EnvironmentVariableGetter
33 static EnvironmentVariableGetter* Create();
34};
35
evan@chromium.org01e3d872009-07-24 07:10:53 +090036enum DesktopEnvironment {
37 DESKTOP_ENVIRONMENT_OTHER,
38 DESKTOP_ENVIRONMENT_GNOME,
mdm@chromium.org6a0e4992009-08-21 08:14:57 +090039 // KDE3 and KDE4 are sufficiently different that we count
40 // them as two different desktop environments here.
41 DESKTOP_ENVIRONMENT_KDE3,
42 DESKTOP_ENVIRONMENT_KDE4,
evan@chromium.org01e3d872009-07-24 07:10:53 +090043};
44
45// Return an entry from the DesktopEnvironment enum with a best guess
46// of which desktop environment we're using. We use this to know when
47// to attempt to use preferences from the desktop environment --
48// proxy settings, password manager, etc.
49DesktopEnvironment GetDesktopEnvironment(EnvironmentVariableGetter* env);
mattm@chromium.org625865e2009-07-22 09:22:49 +090050
mdm@chromium.org6a0e4992009-08-21 08:14:57 +090051// Return a string representation of the given desktop environment.
52// May return NULL in the case of DESKTOP_ENVIRONMENT_OTHER.
53const char* GetDesktopEnvironmentName(DesktopEnvironment env);
54// Convenience wrapper that calls GetDesktopEnvironment() first.
55const char* GetDesktopEnvironmentName(EnvironmentVariableGetter* env);
56
thestig@chromium.org2feb1c82009-10-29 13:02:55 +090057// Return the inode number for the UNIX domain socket |fd|.
58bool FileDescriptorGetInode(ino_t* inode_out, int fd);
59
60// Find the process which holds the given socket, named by inode number. If
61// multiple processes hold the socket, this function returns false.
62bool FindProcessHoldingSocket(pid_t* pid_out, ino_t socket_inode);
63
sgk@google.come1f4a242009-04-22 02:20:10 +090064} // namespace base
65
66#endif // BASE_LINUX_UTIL_H__