1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 2014 Alex Richardson <arichardson.kde@gmail.com>
4
5 SPDX-License-Identifier: LGPL-2.0-only
6*/
7
8#ifndef KIO_KIOGLOBAL_P_H
9#define KIO_KIOGLOBAL_P_H
10
11#include "kiocore_export.h"
12#include <qplatformdefs.h>
13
14#include <KUser>
15
16#ifdef Q_OS_WIN
17// windows just sets the mode_t access rights bits to the same value for user+group+other.
18// This means using the Linux values here is fine.
19#ifndef S_IRUSR
20#define S_IRUSR 0400
21#endif
22#ifndef S_IRGRP
23#define S_IRGRP 0040
24#endif
25#ifndef S_IROTH
26#define S_IROTH 0004
27#endif
28
29#ifndef S_IWUSR
30#define S_IWUSR 0200
31#endif
32#ifndef S_IWGRP
33#define S_IWGRP 0020
34#endif
35#ifndef S_IWOTH
36#define S_IWOTH 0002
37#endif
38
39#ifndef S_IXUSR
40#define S_IXUSR 0100
41#endif
42#ifndef S_IXGRP
43#define S_IXGRP 0010
44#endif
45#ifndef S_IXOTH
46#define S_IXOTH 0001
47#endif
48
49#ifndef S_IRWXU
50#define S_IRWXU S_IRUSR | S_IWUSR | S_IXUSR
51#endif
52#ifndef S_IRWXG
53#define S_IRWXG S_IRGRP | S_IWGRP | S_IXGRP
54#endif
55#ifndef S_IRWXO
56#define S_IRWXO S_IROTH | S_IWOTH | S_IXOTH
57#endif
58Q_STATIC_ASSERT(S_IRUSR == _S_IREAD && S_IWUSR == _S_IWRITE && S_IXUSR == _S_IEXEC);
59
60// these three will never be set in st_mode
61#ifndef S_ISUID
62#define S_ISUID 04000 // SUID bit does not exist on windows
63#endif
64#ifndef S_ISGID
65#define S_ISGID 02000 // SGID bit does not exist on windows
66#endif
67#ifndef S_ISVTX
68#define S_ISVTX 01000 // sticky bit does not exist on windows
69#endif
70
71// Windows does not have S_IFBLK and S_IFSOCK, just use the Linux values, they won't conflict
72#ifndef S_IFBLK
73#define S_IFBLK 0060000
74#endif
75#ifndef S_IFSOCK
76#define S_IFSOCK 0140000
77#endif
78/** performs a QT_STAT and add QT_STAT_LNK to st_mode if the path is a symlink */
79KIOCORE_EXPORT int kio_windows_lstat(const char *path, QT_STATBUF *buffer);
80
81#ifndef QT_LSTAT
82#define QT_LSTAT kio_windows_lstat
83#endif
84
85#ifndef QT_STAT_LNK
86#define QT_STAT_LNK 0120000
87#endif // QT_STAT_LNK
88
89#endif // Q_OS_WIN
90
91namespace KIOPrivate
92{
93/** @return true if the process with given PID is currently running */
94KIOCORE_EXPORT bool isProcessAlive(qint64 pid);
95/** Send a terminate signal (SIGTERM on UNIX) to the process with given PID. */
96KIOCORE_EXPORT void sendTerminateSignal(qint64 pid);
97
98enum SymlinkType {
99 GuessSymlinkType,
100 FileSymlink,
101 DirectorySymlink,
102};
103
104/** Creates a symbolic link at @p destination pointing to @p source
105 * Unlike UNIX, Windows needs to know whether the symlink points to a file or a directory
106 * when creating the link. This information can be passed in @p type. If @p type is not given
107 * the windows code will guess the type based on the source file.
108 * @note On Windows this requires the current user to have the SeCreateSymbolicLink privilege which
109 * is usually only given to administrators.
110 * @return true on success, false on error
111 */
112KIOCORE_EXPORT bool createSymlink(const QString &source, const QString &destination, SymlinkType type = GuessSymlinkType);
113
114/** Changes the ownership of @p file (like chown()) */
115KIOCORE_EXPORT bool changeOwnership(const QString &file, KUserId newOwner, KGroupId newGroup);
116
117/** Returns an icon name for a standard path,
118 * e.g. folder-pictures for any path in QStandardPaths::PicturesLocation */
119QString iconForStandardPath(const QString &localDirectory);
120}
121
122#endif // KIO_KIOGLOBAL_P_H
123

source code of kio/src/core/kioglobal_p.h