mirror of
https://github.com/tianocore/edk2
synced 2026-08-27 00:23:19 -04:00
Replace traditional `#ifndef`/`#define`/`#endif` include guards with
`#pragma` once.
`#pragma once` is a widely supported preprocessor directive that
prevents header files from being included multiple times. It is
supported by all toolchains used to build edk2: GCC, Clang/LLVM, and
MSVC.
Compared to macro-based include guards, `#pragma once`:
- Eliminates the risk of macro name collisions or copy/paste errors
where two headers inadvertently use the same guard macro.
- Eliminate inconsistency in the way include guard macros are named
(e.g., some files use `__FILE_H__`, others use `FILE_H_`, etc.).
- Reduces boilerplate (three lines replaced by one).
- Avoids polluting the macro namespace with guard symbols.
- Can improve build times as the preprocessor can skip re-opening the
file entirely, rather than re-reading it to find the matching
`#endif` ("multiple-include optimization").
- Note that some compilers may already optimize traditional include
guards, by recognzining the idiomatic pattern.
This change is made acknowledging that overall portability of the
code will technically be reduced, as `#pragma once` is not part of the
C/C++ standards.
However, this is considered acceptable given:
1. edk2 already defines a subset of supported compilers in
BaseTools/Conf/tools_def.template, all of which have supported
`#pragma once` for over two decades.
2. There have been concerns raised to the project about inconsistent
include guard naming and potential macro collisions.
Approximate compiler support dates:
- MSVC: Supported since Visual C++ 4.2 (1996)
- GCC: Supported since 3.4 (2004)
(http://gnu.ist.utl.pt/software/gcc/gcc-3.4/changes.html)
- Clang (LLVM based): Since initial release in 2007
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
64 lines
2.1 KiB
C
64 lines
2.1 KiB
C
/** @file
|
|
IP4 option support routines.
|
|
|
|
Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>
|
|
SPDX-License-Identifier: BSD-2-Clause-Patent
|
|
|
|
**/
|
|
|
|
#pragma once
|
|
|
|
#define IP4_OPTION_EOP 0
|
|
#define IP4_OPTION_NOP 1
|
|
#define IP4_OPTION_LSRR 131 // Loss source and record routing, 10000011
|
|
#define IP4_OPTION_SSRR 137 // Strict source and record routing, 10001001
|
|
#define IP4_OPTION_RR 7 // Record routing, 00000111
|
|
|
|
#define IP4_OPTION_COPY_MASK 0x80
|
|
|
|
/**
|
|
Validate the IP4 option format for both the packets we received
|
|
and will transmit. It will compute the ICMP error message fields
|
|
if the option is malformatted. But this information isn't used.
|
|
|
|
@param[in] Option The first byte of the option
|
|
@param[in] OptionLen The length of the whole option
|
|
@param[in] Rcvd The option is from the packet we received if TRUE,
|
|
otherwise the option we wants to transmit.
|
|
|
|
@retval TRUE The option is properly formatted
|
|
@retval FALSE The option is malformatted
|
|
|
|
**/
|
|
BOOLEAN
|
|
Ip4OptionIsValid (
|
|
IN UINT8 *Option,
|
|
IN UINT32 OptionLen,
|
|
IN BOOLEAN Rcvd
|
|
);
|
|
|
|
/**
|
|
Copy the option from the original option to buffer. It
|
|
handles the details such as:
|
|
1. whether copy the single IP4 option to the first/non-first
|
|
fragments.
|
|
2. Pad the options copied over to aligned to 4 bytes.
|
|
|
|
@param[in] Option The original option to copy from
|
|
@param[in] OptionLen The length of the original option
|
|
@param[in] FirstFragment Whether it is the first fragment
|
|
@param[in, out] Buf The buffer to copy options to. NULL
|
|
@param[in, out] BufLen The length of the buffer
|
|
|
|
@retval EFI_SUCCESS The options are copied over
|
|
@retval EFI_BUFFER_TOO_SMALL Buf is NULL or BufLen provided is too small.
|
|
|
|
**/
|
|
EFI_STATUS
|
|
Ip4CopyOption (
|
|
IN UINT8 *Option,
|
|
IN UINT32 OptionLen,
|
|
IN BOOLEAN FirstFragment,
|
|
IN OUT UINT8 *Buf OPTIONAL,
|
|
IN OUT UINT32 *BufLen
|
|
);
|