base/fs/m_fs_perms_unx.c
/* NOTE:
 *   chown takes -1 for uid and gid to signify do not change. However, uid_t and gid_t are
 *   unsigned type so we get a complier warning which is why the -1 is cast. */
chown takes -1 for uid and gid to signify do not change. However, uid_t and gid_t are
unsigned type so we get a complier warning which is why the -1 is cast.
chown takes - 1 for uid and gid to signify do not change . However uid_t and gid_t are unsigned type so we get a complier warning which is why the - 1 is cast .
M_fs_error_t M_fs_perms_set_perms(const M_fs_perms_t *perms, const char *path)
{
	M_fs_info_t  *info;
	char         *norm_path;
	M_fs_error_t  res;
	mode_t        mode = 0;
	if (perms == NULL || path == NULL) {
		return M_FS_ERROR_INVALID;
	}
	res = M_fs_path_norm(&norm_path, path, M_FS_PATH_NORM_RESALL, M_FS_SYSTEM_AUTO);
	if (res != M_FS_ERROR_SUCCESS) {
		M_free(norm_path);
		return res;
	}
	res = M_fs_info(&info, norm_path, M_FS_PATH_INFO_FLAGS_FOLLOW_SYMLINKS);
	if (res != M_FS_ERROR_SUCCESS) {
		M_free(norm_path);
		return res;
	}
	mode = M_fs_perms_to_mode(M_fs_info_get_perms(info), M_FALSE);
	mode = M_fs_perms_update_mode_from_perms(mode, perms, (M_fs_info_get_type(info)==M_FS_TYPE_DIR)?M_TRUE:M_FALSE);
	if (chmod(norm_path, mode) == -1) {
		M_fs_info_destroy(info);
		M_free(norm_path);
		return M_fs_error_from_syserr(errno);
	}
	if (perms->user != NULL || perms->group != NULL) {
		if (chown(norm_path,
				(perms->user != NULL)?perms->uid:(uid_t)-1,
				(perms->group != NULL)?perms->gid:(gid_t)-1)
			== -1)
		{
			M_fs_info_destroy(info);
			M_free(norm_path);
			return M_fs_error_from_syserr(errno);
		}
	}
	M_fs_info_destroy(info);
	M_free(norm_path);
	return M_FS_ERROR_SUCCESS;
}
M_fs_error_t M_fs_perms_set_perms ( const M_fs_perms_t * perms , const char * path ) { M_fs_info_t * info ; char * norm_path ; M_fs_error_t res ; mode_t mode = 0 ; if ( perms == NULL || path == NULL ) { return M_FS_ERROR_INVALID ; } res = M_fs_path_norm ( & norm_path , path , M_FS_PATH_NORM_RESALL , M_FS_SYSTEM_AUTO ) ; if ( res != M_FS_ERROR_SUCCESS ) { M_free ( norm_path ) ; return res ; } res = M_fs_info ( & info , norm_path , M_FS_PATH_INFO_FLAGS_FOLLOW_SYMLINKS ) ; if ( res != M_FS_ERROR_SUCCESS ) { M_free ( norm_path ) ; return res ; } mode = M_fs_perms_to_mode ( M_fs_info_get_perms ( info ) , M_FALSE ) ; mode = M_fs_perms_update_mode_from_perms ( mode , perms , ( M_fs_info_get_type ( info ) == M_FS_TYPE_DIR ) ? M_TRUE : M_FALSE ) ; if ( chmod ( norm_path , mode ) == -1 ) { M_fs_info_destroy ( info ) ; M_free ( norm_path ) ; return M_fs_error_from_syserr ( errno ) ; } if ( perms -> user != NULL || perms -> group != NULL ) { if ( chown ( norm_path , ( perms -> user != NULL ) ? perms -> uid : ( uid_t ) - 1 , ( perms -> group != NULL ) ? perms -> gid : ( gid_t ) - 1 ) == -1 ) { M_fs_info_destroy ( info ) ; M_free ( norm_path ) ; return M_fs_error_from_syserr ( errno ) ; } } M_fs_info_destroy ( info ) ; M_free ( norm_path ) ; return M_FS_ERROR_SUCCESS ; }
NOTE:
   chown takes -1 for uid and gid to signify do not change.
NOTE : chown takes - 1 for uid and gid to signify do not change .