From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id oQ6oJmeqoWkFmQwAWB0awg (envelope-from ) for ; Fri, 27 Feb 2026 09:29:59 -0500 Authentication-Results: simark.ca; dkim=pass (2048-bit key; secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=LtvANhqx; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 98F281E089; Fri, 27 Feb 2026 09:29:59 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id A275A1E089 for ; Fri, 27 Feb 2026 09:29:57 -0500 (EST) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id EA14B4BA2E10 for ; Fri, 27 Feb 2026 14:29:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EA14B4BA2E10 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=LtvANhqx Received: from mail-ot1-x330.google.com (mail-ot1-x330.google.com [IPv6:2607:f8b0:4864:20::330]) by sourceware.org (Postfix) with ESMTPS id D7E134BA2E1D for ; Fri, 27 Feb 2026 14:28:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D7E134BA2E1D Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D7E134BA2E1D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::330 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1772202498; cv=none; b=njlxkBQnBfgzHTbwX74D4ACT1I7lD98uHD10kCtgBymdkzyv3qthNoGjvcRYK3TRj8ldE79YaUNaHUsLVxvLwP+4JgwPLH3NvuT+97eQBvZsp5dxawFaQ/ipdFMY4U9nzQQeCjZgeJ7W/z5YZoHoD3nTeeoejADkZOl7paDn62E= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1772202498; c=relaxed/simple; bh=jefpvFkFVDoA2ClDOUF65A7ZJ2sN/jCnUhxnjyAE2Bc=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=TMINq1sXOAjZowl3Z/p79Twm3Et4kswIGpV20sOzHygYuueNi5F6RLQpk1eeO9IVhJLWXArYMBAJy5Q5ZUXhN/yV+h4QdrUn+IC9nvo3N6bwiFhRRGEbzK4i/cdR/IOeHrTWP/YoBxcN3slp2hcMTo+nLu2irjLS0mMujBWsDkY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D7E134BA2E1D Received: by mail-ot1-x330.google.com with SMTP id 46e09a7af769-7d4be7c4ebeso209082a34.1 for ; Fri, 27 Feb 2026 06:28:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1772202497; x=1772807297; darn=sourceware.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=UvnnITvtu7MdwxJDu1Upjl0QPyQce2vcPF9T4imeuSE=; b=LtvANhqx5NrpMeoWLAQ7OxCiqaxI2d8WOX9isaAtoK3gC/DlDxVHInfuBkhzTPpNul GUe8lAq65KONx5jjFRaOdWOG0J8MG/aNs5QKxrbU7PwGa1lZ9CQnfdZBBJBegnN3NeHp qHCc4oPYr2vtp2vQBYTWIoRq3IeM3K8drcaAXnbusXpA2WkpfUgicL3fVDb0mhHm7krx huyxtOp7d0X++0uEk8H1DYesaXIJAOfTMRBYxhaNePucVyQPq+BkKR59/gfCUmYHHR4+ mtwAEIbsMax/jdDWuhAg1kon+Xfd/NpIa9heSsdUVLBZCB/jGA39uUaPUf8HYOBGDrND g1/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772202497; x=1772807297; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=UvnnITvtu7MdwxJDu1Upjl0QPyQce2vcPF9T4imeuSE=; b=iDJaxabFObiuK6rLQs74KSPT5wET0xI/XbgR/xN1MMl9YKHQJLIfbqxEXRp+Cmo7Ds DyPjF0d6J3tJS+EYOKr/kKLzq93tN5RGGRu3Y5/A2/pUg9gJ1Wb6poxQNj3QkiRzqU7r Y8OOYBt+hTZKFIvUOPgvJzQhJ9vX86eqqe5fg7RvvtuihmCPrJLMjfGRKLg1wIpztA5e q6abecZEmTXXhVYiNlB0m7qYHbUy1Ssa2ViKae0ZwxmWJm3oNf44g4BsgdcfT2yX/TLd AJz8biavAWNmOfU0rxNb6XIoaEeFgUe61h3w+Pv5a5o2mVEzP64sAi67zrg4z1THcxhC 5zNg== X-Gm-Message-State: AOJu0YxF/rgNqjOmOBf/z92DsODUfPsL0B0ukwNHhyD37liQvrXOxGHv OV9Cnu54ogPz8JzkF4nSukxc8mfSeSYWHGOQR2nDwQsCIU3D8jYZfx9FlXjG+yj6NRVSoQ7vS1e LB6E= X-Gm-Gg: ATEYQzxxxcohXPHkX+nNt9nVhBZBUglSDFYIFYg/XPZGbecWTwbFBWDABzNaVOOUPx0 3uvk57WuRpeAen0Sjj2O2YYIv5Z0vm2dYYJJvl9UHE7I9vtL1Xe3XAYnMq4nMIFi/YRzKYlM+wP nb1xKG+XM1zjqQzBwslC2gvdA3R7dDygW+LUZQNEXU4sS9F8xKfrChxXJBMMb5oBdAY0/X0ttJq zo9salcdKOIL/9fnv+3Wnj/ISHqgZ9kxKavcu5uc+DX33lnQNXVSjvkI2wrcbuHLvBCoWZTQdAs 7/reijHqJuJ99oawskLemy8K0NAQo6AvbrcWFIQpWSJorJFER4Gv/9BS/US4t18bDJqTfSa3Icy Sb8keq7+BKpCeeCNOIxPuLvBDZKYuRiqtWd67n5yaxHDxs/qfEf6aJzrroiLJLp52fk+eKy+ieI zg0snKfsIKp+UCCwF19FbDFUmzus4skk0t4mNcIzeatBSQstd2XASWxfG4 X-Received: by 2002:a05:6830:280b:b0:7cf:d819:a2d2 with SMTP id 46e09a7af769-7d591bf8f12mr1977966a34.31.1772202497016; Fri, 27 Feb 2026 06:28:17 -0800 (PST) Received: from [192.168.0.26] (97-122-122-234.hlrn.qwest.net. [97.122.122.234]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7d58666f30esm4304322a34.26.2026.02.27.06.28.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Feb 2026 06:28:16 -0800 (PST) From: Tom Tromey Date: Fri, 27 Feb 2026 07:28:14 -0700 Subject: [PATCH v2 2/3] Use enum types for remote fileio flags MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260227-target-fd-newtype-v2-2-7a266666ae36@adacore.com> References: <20260227-target-fd-newtype-v2-0-7a266666ae36@adacore.com> In-Reply-To: <20260227-target-fd-newtype-v2-0-7a266666ae36@adacore.com> To: gdb-patches@sourceware.org Cc: Tom Tromey X-Mailer: b4 0.14.3 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org This changes gdbsupport/fileio.h to use enums with underlying types for the various constants -- open flags, modes, and lseek flags. These types replace #defines that were previously used. Then, this fixes all the users of these flags. This found a few bugs. Some of these were pedantic (using the constant 0700 where perhaps FILEIO_S_IRWXU would be more precise), but sparc64-tdep.c confused host and remote flags. Also, I believe solib-rocm.c had a couple of arguments in the wrong order. Once again, the solib-rocm.c changes are best-effort, as I can't compile this file. I also found that gdb/remote-fileio.c had essentially duplicated some code from gdbsupport. This patch removes the duplicates. New in v2: - The lseek enum is anonymous, the type itself isn't used, just the constants --- gdb/inf-child.c | 4 +-- gdb/inf-child.h | 4 +-- gdb/linux-nat.c | 4 +-- gdb/linux-nat.h | 4 +-- gdb/remote-fileio.c | 91 +++++++++------------------------------------------- gdb/remote.c | 19 ++++++----- gdb/sparc64-tdep.c | 6 ++-- gdb/target.c | 12 ++++--- gdb/target.h | 10 +++--- gdbserver/hostio.cc | 4 +-- gdbsupport/fileio.cc | 20 ++++++------ gdbsupport/fileio.h | 85 +++++++++++++++++++++++++++--------------------- 12 files changed, 112 insertions(+), 151 deletions(-) diff --git a/gdb/inf-child.c b/gdb/inf-child.c index 934d8c2ba09..22e52686d5e 100644 --- a/gdb/inf-child.c +++ b/gdb/inf-child.c @@ -233,8 +233,8 @@ inf_child_target::pid_to_exec_file (int pid) int inf_child_target::fileio_open (struct inferior *inf, const char *filename, - int flags, int mode, int warn_if_slow, - fileio_error *target_errno) + fileio_open_flags flags, fileio_mode_flags mode, + int warn_if_slow, fileio_error *target_errno) { int nat_flags; mode_t nat_mode; diff --git a/gdb/inf-child.h b/gdb/inf-child.h index bb18f08dbcf..7d2d4eab68e 100644 --- a/gdb/inf-child.h +++ b/gdb/inf-child.h @@ -74,8 +74,8 @@ class inf_child_target const char *pid_to_exec_file (int pid) override; int fileio_open (struct inferior *inf, const char *filename, - int flags, int mode, int warn_if_slow, - fileio_error *target_errno) override; + fileio_open_flags flags, fileio_mode_flags mode, + int warn_if_slow, fileio_error *target_errno) override; int fileio_pwrite (int fd, const gdb_byte *write_buf, int len, ULONGEST offset, fileio_error *target_errno) override; int fileio_pread (int fd, gdb_byte *read_buf, int len, diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c index 958b367f4ea..22dbfbc31f9 100644 --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -4572,8 +4572,8 @@ linux_nat_fileio_pid_of (struct inferior *inf) int linux_nat_target::fileio_open (struct inferior *inf, const char *filename, - int flags, int mode, int warn_if_slow, - fileio_error *target_errno) + fileio_open_flags flags, fileio_mode_flags mode, + int warn_if_slow, fileio_error *target_errno) { int nat_flags; mode_t nat_mode; diff --git a/gdb/linux-nat.h b/gdb/linux-nat.h index 4641615d531..2d2ccbc2371 100644 --- a/gdb/linux-nat.h +++ b/gdb/linux-nat.h @@ -100,8 +100,8 @@ class linux_nat_target : public inf_ptrace_target bool filesystem_is_local () override; int fileio_open (struct inferior *inf, const char *filename, - int flags, int mode, int warn_if_slow, - fileio_error *target_errno) override; + fileio_open_flags flags, fileio_mode_flags mode, + int warn_if_slow, fileio_error *target_errno) override; std::optional fileio_readlink (struct inferior *inf, diff --git a/gdb/remote-fileio.c b/gdb/remote-fileio.c index 459f249d37b..30afc3737ab 100644 --- a/gdb/remote-fileio.c +++ b/gdb/remote-fileio.c @@ -120,78 +120,6 @@ remote_fileio_close_target_fd (int target_fd) remote_fio_data.fd_map[target_fd] = FIO_FD_INVALID; } -static int -remote_fileio_oflags_to_host (long flags) -{ - int hflags = 0; - - if (flags & FILEIO_O_CREAT) - hflags |= O_CREAT; - if (flags & FILEIO_O_EXCL) - hflags |= O_EXCL; - if (flags & FILEIO_O_TRUNC) - hflags |= O_TRUNC; - if (flags & FILEIO_O_APPEND) - hflags |= O_APPEND; - if (flags & FILEIO_O_RDONLY) - hflags |= O_RDONLY; - if (flags & FILEIO_O_WRONLY) - hflags |= O_WRONLY; - if (flags & FILEIO_O_RDWR) - hflags |= O_RDWR; -/* On systems supporting binary and text mode, always open files in - binary mode. */ -#ifdef O_BINARY - hflags |= O_BINARY; -#endif - return hflags; -} - -static mode_t -remote_fileio_mode_to_host (long mode, int open_call) -{ - mode_t hmode = 0; - - if (!open_call) - { - if (mode & FILEIO_S_IFREG) - hmode |= S_IFREG; - if (mode & FILEIO_S_IFDIR) - hmode |= S_IFDIR; - if (mode & FILEIO_S_IFCHR) - hmode |= S_IFCHR; - } - if (mode & FILEIO_S_IRUSR) - hmode |= S_IRUSR; - if (mode & FILEIO_S_IWUSR) - hmode |= S_IWUSR; - if (mode & FILEIO_S_IXUSR) - hmode |= S_IXUSR; -#ifdef S_IRGRP - if (mode & FILEIO_S_IRGRP) - hmode |= S_IRGRP; -#endif -#ifdef S_IWGRP - if (mode & FILEIO_S_IWGRP) - hmode |= S_IWGRP; -#endif -#ifdef S_IXGRP - if (mode & FILEIO_S_IXGRP) - hmode |= S_IXGRP; -#endif - if (mode & FILEIO_S_IROTH) - hmode |= S_IROTH; -#ifdef S_IWOTH - if (mode & FILEIO_S_IWOTH) - hmode |= S_IWOTH; -#endif -#ifdef S_IXOTH - if (mode & FILEIO_S_IXOTH) - hmode |= S_IXOTH; -#endif - return hmode; -} - static int remote_fileio_seek_flag_to_host (long num, int *flag) { @@ -391,14 +319,23 @@ remote_fileio_func_open (remote_target *remote, char *buf) remote_fileio_ioerror (remote); return; } - flags = remote_fileio_oflags_to_host (num); + if (fileio_to_host_openflags ((enum fileio_open_flag) num, &flags)) + { + remote_fileio_ioerror (remote); + return; + } + /* 3. Parameter: open mode */ if (remote_fileio_extract_int (&buf, &num)) { remote_fileio_ioerror (remote); return; } - mode = remote_fileio_mode_to_host (num, 1); + if (fileio_to_host_mode (fileio_mode_flag (num), &mode)) + { + remote_fileio_ioerror (remote); + return; + } /* Request pathname. */ pathname = (char *) alloca (length); @@ -1233,8 +1170,10 @@ remote_fileio_to_host_ulong (fio_ulong_t fnum) static mode_t remote_fileio_to_host_mode (fio_mode_t fnum) { - return remote_fileio_mode_to_host (remote_fileio_to_host_uint (fnum), - 0); + mode_t result; + ULONGEST conv = remote_fileio_to_host_uint (fnum); + fileio_to_host_mode ((fileio_mode_flag) conv, &result); + return result; } /* Unpack an fio_time_t. */ diff --git a/gdb/remote.c b/gdb/remote.c index a5fb16381b1..04b24f0a703 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -1114,7 +1114,8 @@ class remote_target : public process_stratum_target int fileio_open (struct inferior *inf, const char *filename, - int flags, int mode, int warn_if_slow, + fileio_open_flags flags, fileio_mode_flags mode, + int warn_if_slow, fileio_error *target_errno) override; int fileio_pwrite (int fd, const gdb_byte *write_buf, int len, @@ -1289,8 +1290,8 @@ class remote_target : public process_stratum_target fileio_error *remote_errno); /* We should get rid of this and use fileio_open directly. */ int remote_hostio_open (struct inferior *inf, const char *filename, - int flags, int mode, int warn_if_slow, - fileio_error *remote_errno); + fileio_open_flags flags, fileio_mode_flags mode, + int warn_if_slow, fileio_error *remote_errno); int remote_hostio_close (int fd, fileio_error *remote_errno); int remote_hostio_unlink (inferior *inf, const char *filename, @@ -13400,7 +13401,9 @@ remote_target::remote_hostio_set_filesystem (struct inferior *inf, int remote_target::remote_hostio_open (inferior *inf, const char *filename, - int flags, int mode, int warn_if_slow, + fileio_open_flags flags, + fileio_mode_flags mode, + int warn_if_slow, fileio_error *remote_errno) { struct remote_state *rs = get_remote_state (); @@ -13446,8 +13449,8 @@ remote_target::remote_hostio_open (inferior *inf, const char *filename, int remote_target::fileio_open (struct inferior *inf, const char *filename, - int flags, int mode, int warn_if_slow, - fileio_error *remote_errno) + fileio_open_flags flags, fileio_mode_flags mode, + int warn_if_slow, fileio_error *remote_errno) { return remote_hostio_open (inf, filename, flags, mode, warn_if_slow, remote_errno); @@ -13828,7 +13831,7 @@ remote_target::filesystem_is_local () filename is irrelevant, we only care about whether the stub recognizes the packet or not. */ fd = remote_hostio_open (NULL, "just probing", - FILEIO_O_RDONLY, 0700, 0, + FILEIO_O_RDONLY, FILEIO_S_IRWXU, 0, &remote_errno); if (fd >= 0) @@ -13960,7 +13963,7 @@ remote_target::remote_file_put (const char *local_file, const char *remote_file, (this, remote_hostio_open (NULL, remote_file, (FILEIO_O_WRONLY | FILEIO_O_CREAT | FILEIO_O_TRUNC), - 0700, 0, &remote_errno)); + FILEIO_S_IRWXU, 0, &remote_errno)); if (fd.get () == -1) remote_hostio_error (remote_errno); diff --git a/gdb/sparc64-tdep.c b/gdb/sparc64-tdep.c index e4d06eeef61..88bc0ba3ad4 100644 --- a/gdb/sparc64-tdep.c +++ b/gdb/sparc64-tdep.c @@ -287,8 +287,10 @@ adi_tag_fd () char cl_name[MAX_PROC_NAME_SIZE]; snprintf (cl_name, sizeof(cl_name), "/proc/%ld/adi/tags", (long) pid); fileio_error target_errno; - proc->stat.tag_fd = target_fileio_open (NULL, cl_name, O_RDWR|O_EXCL, - false, 0, &target_errno); + proc->stat.tag_fd = target_fileio_open (NULL, cl_name, + FILEIO_O_RDWR | FILEIO_O_EXCL, + 0, false, + &target_errno); return proc->stat.tag_fd; } diff --git a/gdb/target.c b/gdb/target.c index 5264b0fb04b..611f37c9730 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -3176,8 +3176,8 @@ fileio_fd_to_fh (target_fd fd) int target_ops::fileio_open (struct inferior *inf, const char *filename, - int flags, int mode, int warn_if_slow, - fileio_error *target_errno) + fileio_open_flags flags, fileio_mode_flags mode, + int warn_if_slow, fileio_error *target_errno) { *target_errno = FILEIO_ENOSYS; return -1; @@ -3241,7 +3241,8 @@ target_ops::fileio_readlink (struct inferior *inf, const char *filename, target_fd target_fileio_open (struct inferior *inf, const char *filename, - int flags, int mode, bool warn_if_slow, fileio_error *target_errno) + fileio_open_flags flags, fileio_mode_flags mode, + bool warn_if_slow, fileio_error *target_errno) { for (target_ops *t = default_fileio_target (); t != NULL; t = t->beneath ()) { @@ -3260,7 +3261,7 @@ target_fileio_open (struct inferior *inf, const char *filename, target_debug_printf_nofunc ("target_fileio_open (%d,%s,0x%x,0%o,%d) = %d (%d)", inf == NULL ? 0 : inf->num, filename, - flags, mode, warn_if_slow, int (result), + unsigned (flags), unsigned (mode), warn_if_slow, int (result), result != target_fd::INVALID ? 0 : *target_errno); return result; } @@ -3480,7 +3481,8 @@ target_fileio_read_alloc_1 (struct inferior *inf, const char *filename, fileio_error target_errno; scoped_target_fd fd (target_fileio_open (inf, filename, FILEIO_O_RDONLY, - 0700, false, &target_errno)); + FILEIO_S_IRWXU, false, + &target_errno)); if (fd.get () == target_fd::INVALID) return -1; diff --git a/gdb/target.h b/gdb/target.h index f76ac09ee82..89f6180b9e5 100644 --- a/gdb/target.h +++ b/gdb/target.h @@ -991,8 +991,8 @@ struct target_ops target file descriptor, or -1 if an error occurs (and set *TARGET_ERRNO). */ virtual int fileio_open (struct inferior *inf, const char *filename, - int flags, int mode, int warn_if_slow, - fileio_error *target_errno); + fileio_open_flags flags, fileio_mode_flags mode, + int warn_if_slow, fileio_error *target_errno); /* Write up to LEN bytes from WRITE_BUF to FD on the target. Return the number of bytes written, or -1 if an error occurs @@ -2264,8 +2264,10 @@ enum class target_fd : int *TARGET_ERRNO). If WARN_IF_SLOW is true, print a warning message if the file is being accessed over a link that may be slow. */ extern target_fd target_fileio_open (struct inferior *inf, - const char *filename, int flags, - int mode, bool warn_if_slow, + const char *filename, + fileio_open_flags flags, + fileio_mode_flags mode, + bool warn_if_slow, fileio_error *target_errno); /* Write up to LEN bytes from WRITE_BUF to FD on the target. diff --git a/gdbserver/hostio.cc b/gdbserver/hostio.cc index a0a0735deb4..b9ca27c2ff4 100644 --- a/gdbserver/hostio.cc +++ b/gdbserver/hostio.cc @@ -318,8 +318,8 @@ handle_open (char *own_buf) || require_comma (&p) || require_int (&p, &fileio_mode) || require_end (p) - || fileio_to_host_openflags (fileio_flags, &flags) - || fileio_to_host_mode (fileio_mode, &mode)) + || fileio_to_host_openflags (fileio_open_flag (fileio_flags), &flags) + || fileio_to_host_mode (fileio_mode_flag (fileio_mode), &mode)) { hostio_packet_error (own_buf); return; diff --git a/gdbsupport/fileio.cc b/gdbsupport/fileio.cc index aedb67335ec..6d2ffb14544 100644 --- a/gdbsupport/fileio.cc +++ b/gdbsupport/fileio.cc @@ -130,26 +130,26 @@ fileio_error_to_host (fileio_error errnum) /* See fileio.h. */ int -fileio_to_host_openflags (int fileio_open_flags, int *open_flags_p) +fileio_to_host_openflags (fileio_open_flags fflags, int *open_flags_p) { int open_flags = 0; - if (fileio_open_flags & ~FILEIO_O_SUPPORTED) + if (fflags & ~FILEIO_O_SUPPORTED) return -1; - if (fileio_open_flags & FILEIO_O_CREAT) + if (fflags & FILEIO_O_CREAT) open_flags |= O_CREAT; - if (fileio_open_flags & FILEIO_O_EXCL) + if (fflags & FILEIO_O_EXCL) open_flags |= O_EXCL; - if (fileio_open_flags & FILEIO_O_TRUNC) + if (fflags & FILEIO_O_TRUNC) open_flags |= O_TRUNC; - if (fileio_open_flags & FILEIO_O_APPEND) + if (fflags & FILEIO_O_APPEND) open_flags |= O_APPEND; - if (fileio_open_flags & FILEIO_O_RDONLY) + if (fflags & FILEIO_O_RDONLY) open_flags |= O_RDONLY; - if (fileio_open_flags & FILEIO_O_WRONLY) + if (fflags & FILEIO_O_WRONLY) open_flags |= O_WRONLY; - if (fileio_open_flags & FILEIO_O_RDWR) + if (fflags & FILEIO_O_RDWR) open_flags |= O_RDWR; /* On systems supporting binary and text mode, always open files in binary mode. */ @@ -164,7 +164,7 @@ fileio_to_host_openflags (int fileio_open_flags, int *open_flags_p) /* See fileio.h. */ int -fileio_to_host_mode (int fileio_mode, mode_t *mode_p) +fileio_to_host_mode (fileio_mode_flags fileio_mode, mode_t *mode_p) { mode_t mode = 0; diff --git a/gdbsupport/fileio.h b/gdbsupport/fileio.h index f7b1bdf6375..bb70e404bba 100644 --- a/gdbsupport/fileio.h +++ b/gdbsupport/fileio.h @@ -21,6 +21,7 @@ #define GDBSUPPORT_FILEIO_H #include +#include "enum-flags.h" /* The following flags are defined to be independent of the host as well as the target side implementation of these constants. @@ -29,42 +30,53 @@ corresponding implementation dependent constants in one module. */ /* open(2) flags */ -#define FILEIO_O_RDONLY 0x0 -#define FILEIO_O_WRONLY 0x1 -#define FILEIO_O_RDWR 0x2 -#define FILEIO_O_APPEND 0x8 -#define FILEIO_O_CREAT 0x200 -#define FILEIO_O_TRUNC 0x400 -#define FILEIO_O_EXCL 0x800 -#define FILEIO_O_SUPPORTED (FILEIO_O_RDONLY | FILEIO_O_WRONLY| \ - FILEIO_O_RDWR | FILEIO_O_APPEND| \ - FILEIO_O_CREAT | FILEIO_O_TRUNC| \ - FILEIO_O_EXCL) +enum fileio_open_flag : unsigned +{ + FILEIO_O_RDONLY = 0x0, + FILEIO_O_WRONLY = 0x1, + FILEIO_O_RDWR = 0x2, + FILEIO_O_APPEND = 0x8, + FILEIO_O_CREAT = 0x200, + FILEIO_O_TRUNC = 0x400, + FILEIO_O_EXCL = 0x800, + FILEIO_O_SUPPORTED = (FILEIO_O_RDONLY | FILEIO_O_WRONLY + | FILEIO_O_RDWR | FILEIO_O_APPEND + | FILEIO_O_CREAT | FILEIO_O_TRUNC + | FILEIO_O_EXCL), +}; +DEF_ENUM_FLAGS_TYPE (enum fileio_open_flag, fileio_open_flags); /* mode_t bits */ -#define FILEIO_S_IFREG 0100000 -#define FILEIO_S_IFDIR 040000 -#define FILEIO_S_IFCHR 020000 -#define FILEIO_S_IRUSR 0400 -#define FILEIO_S_IWUSR 0200 -#define FILEIO_S_IXUSR 0100 -#define FILEIO_S_IRWXU 0700 -#define FILEIO_S_IRGRP 040 -#define FILEIO_S_IWGRP 020 -#define FILEIO_S_IXGRP 010 -#define FILEIO_S_IRWXG 070 -#define FILEIO_S_IROTH 04 -#define FILEIO_S_IWOTH 02 -#define FILEIO_S_IXOTH 01 -#define FILEIO_S_IRWXO 07 -#define FILEIO_S_SUPPORTED (FILEIO_S_IFREG|FILEIO_S_IFDIR| \ - FILEIO_S_IRWXU|FILEIO_S_IRWXG| \ - FILEIO_S_IRWXO) +enum fileio_mode_flag : unsigned +{ + FILEIO_S_IFREG = 0100000, + FILEIO_S_IFDIR = 040000, + FILEIO_S_IFCHR = 020000, + FILEIO_S_IRUSR = 0400, + FILEIO_S_IWUSR = 0200, + FILEIO_S_IXUSR = 0100, + FILEIO_S_IRWXU = 0700, + FILEIO_S_IRGRP = 040, + FILEIO_S_IWGRP = 020, + FILEIO_S_IXGRP = 010, + FILEIO_S_IRWXG = 070, + FILEIO_S_IROTH = 04, + FILEIO_S_IWOTH = 02, + FILEIO_S_IXOTH = 01, + FILEIO_S_IRWXO = 07, + FILEIO_S_SUPPORTED = (FILEIO_S_IFREG | FILEIO_S_IFDIR + | FILEIO_S_IRWXU | FILEIO_S_IRWXG + | FILEIO_S_IRWXO), +}; +DEF_ENUM_FLAGS_TYPE (enum fileio_mode_flag, fileio_mode_flags); /* lseek(2) flags */ -#define FILEIO_SEEK_SET 0 -#define FILEIO_SEEK_CUR 1 -#define FILEIO_SEEK_END 2 +enum +{ + FILEIO_SEEK_SET = 0, + FILEIO_SEEK_CUR = 1, + FILEIO_SEEK_END = 2, +}; /* errno values */ enum fileio_error @@ -144,14 +156,15 @@ extern fileio_error host_to_fileio_error (int error); extern int fileio_error_to_host (fileio_error errnum); /* Convert File-I/O open flags FFLAGS to host format, storing - the result in *FLAGS. Return 0 on success, -1 on error. */ + the result in *OPEN_FLAGS_P. Return 0 on success, -1 on error. */ -extern int fileio_to_host_openflags (int fflags, int *flags); +extern int fileio_to_host_openflags (fileio_open_flags fflags, + int *open_flags_p); /* Convert File-I/O mode FMODE to host format, storing - the result in *MODE. Return 0 on success, -1 on error. */ + the result in *MODE_P. Return 0 on success, -1 on error. */ -extern int fileio_to_host_mode (int fmode, mode_t *mode); +extern int fileio_to_host_mode (fileio_mode_flags fmode, mode_t *mode_p); /* Pack a host-format integer into a byte buffer in big-endian format. BYTES specifies the size of the integer to pack in -- 2.53.0