Change owner implies changing the owner.
This is not strictly true, due to how the chown() and similar POSIX functions works.
Instead, these change owner and/or group.
To avoid confusion with thinking this function exclusively changes owner, use a completely different word.
The chosen word is "role".
}
#endif // _di_f_file_change_mode_at_
-#ifndef _di_f_file_change_owner_
- f_return_status f_file_change_owner(const f_string path, const uid_t uid, const gid_t gid, const bool dereference) {
+#ifndef _di_f_file_change_role_
+ f_return_status f_file_change_role(const f_string path, const uid_t uid, const gid_t gid, const bool dereference) {
#ifndef _di_level_0_parameter_checking_
if (path == 0) return F_status_set_error(F_parameter);
if (uid < 0 && gid < 0) return F_status_set_error(F_parameter);
if (uid < -1 || gid < -1) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
- return private_f_file_change_owner(path, uid, gid, dereference);
+ return private_f_file_change_role(path, uid, gid, dereference);
}
-#endif // _di_f_file_change_owner_
+#endif // _di_f_file_change_role_
-#ifndef _di_f_file_change_owner_at_
- f_return_status f_file_change_owner_at(const int at_id, const f_string path, const uid_t uid, const gid_t gid, const int flag) {
+#ifndef _di_f_file_change_role_at_
+ f_return_status f_file_change_role_at(const int at_id, const f_string path, const uid_t uid, const gid_t gid, const int flag) {
#ifndef _di_level_0_parameter_checking_
if (path == 0) return F_status_set_error(F_parameter);
if (uid < 0 && gid < 0) return F_status_set_error(F_parameter);
if (uid < -1 || gid < -1) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
- return private_f_file_change_owner_at(at_id, path, uid, gid, flag);
+ return private_f_file_change_role_at(at_id, path, uid, gid, flag);
}
-#endif // _di_f_file_change_owner_at_
+#endif // _di_f_file_change_role_at_
#ifndef _di_f_file_clone_
f_return_status f_file_clone(const f_string source, const f_string destination, const bool role, const f_number_unsigned size_block, const bool exclusive) {
}
if (role) {
- status = private_f_file_change_owner(destination, source_stat.st_uid, source_stat.st_gid, F_false);
+ status = private_f_file_change_role(destination, source_stat.st_uid, source_stat.st_gid, F_false);
if (F_status_is_error(status)) return status;
}
if (F_status_is_error(status)) return status;
if (role) {
- status = private_f_file_change_owner(destination, source_stat.st_uid, source_stat.st_gid, F_false);
+ status = private_f_file_change_role(destination, source_stat.st_uid, source_stat.st_gid, F_false);
if (F_status_is_error(status)) return status;
}
#endif // _di_f_file_change_mode_at_
/**
- * Change owner and group of a given file at the specified path.
+ * Change owner and/or group of a given file at the specified path.
+ *
+ * At least one of uid or gid must not be -1.
*
* @param path
* The path file name.
* @param uid
* The new user id to use.
+ * Set to -1 to not change.
* @param gid
* The new group id to use.
+ * Set to -1 to not change.
* @param dereference
* Set to TRUE to dereferenc symlinks (often is what is desired).
* Set to FALSE to operate on the symlink itself.
* @see chown()
* @see lchown()
*/
-#ifndef _di_f_file_change_owner_
- extern f_return_status f_file_change_owner(const f_string path, const uid_t uid, const gid_t gid, const bool dereference);
-#endif // _di_f_file_change_owner_
+#ifndef _di_f_file_change_role_
+ extern f_return_status f_file_change_role(const f_string path, const uid_t uid, const gid_t gid, const bool dereference);
+#endif // _di_f_file_change_role_
/**
- * Change owner and group of a given file at the specified path.
+ * Change owner and/or group of a given file at the specified path.
+ *
+ * At least one of uid or gid must not be -1.
*
* @param at_id
* The parent directory, as an open directory file descriptor, in which path is relative to.
* The path file name.
* @param uid
* The new user id to use.
+ * Set to -1 to not change.
* @param gid
* The new group id to use.
+ * Set to -1 to not change.
* @param flag
* Any valid flag, such as f_file_at_path_empty, f_file_at_automount_no, or f_file_at_symlink_follow_no.
*
*
* @see fchownat()
*/
-#ifndef _di_f_file_change_owner_at_
- extern f_return_status f_file_change_owner_at(const int at_id, const f_string path, const uid_t uid, const gid_t gid, const int flag);
-#endif // _di_f_file_change_owner_at_
+#ifndef _di_f_file_change_role_at_
+ extern f_return_status f_file_change_role_at(const int at_id, const f_string path, const uid_t uid, const gid_t gid, const int flag);
+#endif // _di_f_file_change_role_at_
/**
* Copy a file, as well as its file mode and possibly the owner and group.
}
#endif // !defined(_di_f_file_change_mode_at_) || !defined(_di_f_file_copy_at_)
-#if !defined(_di_f_file_change_owner_) || !defined(_di_f_file_copy_)
- f_return_status private_f_file_change_owner(const f_string path, const uid_t uid, const gid_t gid, const bool dereference) {
+#if !defined(_di_f_file_change_role_) || !defined(_di_f_file_copy_)
+ f_return_status private_f_file_change_role(const f_string path, const uid_t uid, const gid_t gid, const bool dereference) {
int result = 0;
if (dereference) {
return F_none;
}
-#endif // !defined(_di_f_file_change_owner_) || !defined(_di_f_file_copy_)
+#endif // !defined(_di_f_file_change_role_) || !defined(_di_f_file_copy_)
-#if !defined(_di_f_file_change_owner_at_) || !defined(_di_f_file_copy_at_)
- f_return_status private_f_file_change_owner_at(const int at_id, const f_string path, const uid_t uid, const gid_t gid, const int flag) {
+#if !defined(_di_f_file_change_role_at_) || !defined(_di_f_file_copy_at_)
+ f_return_status private_f_file_change_role_at(const int at_id, const f_string path, const uid_t uid, const gid_t gid, const int flag) {
int result = 0;
if (uid != -1) {
return F_none;
}
-#endif // !defined(_di_f_file_change_owner_at_) || !defined(_di_f_file_copy_at_)
+#endif // !defined(_di_f_file_change_role_at_) || !defined(_di_f_file_copy_at_)
#if !defined(_di_f_file_close_) || !defined(_di_f_file_copy_)
f_return_status private_f_file_close(int *id) {
#endif // !defined(_di_f_file_change_mode_at_)
/**
- * Private implementation of f_file_change_owner().
+ * Private implementation of f_file_change_role().
*
* Intended to be shared to each of the different implementation variations.
*
* F_read_only (with error bit) if file is read-only.
* F_failure (with error bit) for any other error.
*
- * @see f_file_change_owner()
+ * @see f_file_change_role()
* @see f_file_copy()
*/
-#if !defined(_di_f_file_change_owner_) || !defined(_di_f_file_copy_)
- extern f_return_status private_f_file_change_owner(const f_string path, const uid_t uid, const gid_t gid, const bool dereference) f_gcc_attribute_visibility_internal;
-#endif // !defined(_di_f_file_change_owner_) || !defined(_di_f_file_copy_)
+#if !defined(_di_f_file_change_role_) || !defined(_di_f_file_copy_)
+ extern f_return_status private_f_file_change_role(const f_string path, const uid_t uid, const gid_t gid, const bool dereference) f_gcc_attribute_visibility_internal;
+#endif // !defined(_di_f_file_change_role_) || !defined(_di_f_file_copy_)
/**
- * Private implementation of f_file_change_owner_at().
+ * Private implementation of f_file_change_role_at().
*
* Intended to be shared to each of the different implementation variations.
*
* F_read_only (with error bit) if file is read-only.
* F_failure (with error bit) for any other error.
*
- * @see f_file_change_owner_at()
+ * @see f_file_change_role_at()
*/
-#if !defined(_di_f_file_change_owner_at_)
- extern f_return_status private_f_file_change_owner_at(const int at_id, const f_string path, const uid_t uid, const gid_t gid, const int flag) f_gcc_attribute_visibility_internal;
-#endif // !defined(_di_f_file_change_owner_at_)
+#if !defined(_di_f_file_change_role_at_)
+ extern f_return_status private_f_file_change_role_at(const int at_id, const f_string path, const uid_t uid, const gid_t gid, const int flag) f_gcc_attribute_visibility_internal;
+#endif // !defined(_di_f_file_change_role_at_)
/**
* Private implementation of f_file_close().
}
if (role) {
- status = f_file_change_owner(destination, source_stat.st_uid, source_stat.st_gid, F_true);
+ status = f_file_change_role(destination, source_stat.st_uid, source_stat.st_gid, F_true);
if (F_status_is_error(status)) return status;
}
* Errors from (with error bit): f_directory_create().
* Errors from (with error bit): f_directory_exists().
* Errors from (with error bit): f_file_change_mode().
- * Errors from (with error bit): f_file_change_owner().
+ * Errors from (with error bit): f_file_change_role().
* Errors from (with error bit): f_file_stat().
*
* @see f_file_clone()
* Errors from (with error bit): f_directory_create().
* Errors from (with error bit): f_directory_exists().
* Errors from (with error bit): f_file_change_mode().
- * Errors from (with error bit): f_file_change_owner().
+ * Errors from (with error bit): f_file_change_role().
* Errors from (with error bit): f_file_stat().
*
* @see f_file_copy()
}
if (role) {
- status = f_file_change_owner(destination_sub.string, source_stat.st_uid, source_stat.st_gid, F_true);
+ status = f_file_change_role(destination_sub.string, source_stat.st_uid, source_stat.st_gid, F_true);
if (F_status_is_error(status)) break;
}
}