On Tue, 2016-05-24 at 16:55 +0200, Martin Kosek wrote:
> On 05/24/2016 04:29 PM, Nathaniel McCallum wrote:
> > Using a pragma instead of guards is easier to write, less error
> > prone
> > and avoids name clashes (a source of very subtle bugs). This pragma
> > is supported on almost all compilers, including all the compilers
> > we
> > care about: https://en.wikipedia.org/wiki/Pragma_once#Portability.
> > 
> > 
> > 
> 
> Makes sense to me. I did not test, just saw a potential
> typo/omission:
> 
> --- a/daemons/ipa-otpd/internal.h
> +++ b/daemons/ipa-otpd/internal.h
> @@ -20,9 +20,6 @@
>   * along with this program.  If not, see <http://www.gnu.org/license
> s/>.
>   */
> 
> -#ifndef INTERNAL_H_
> -#define INTERNAL_H_
> -
> 
> 
> ... no pragma there.

Fixed.
From eec4b7e47b4aaf92bbb194b6acd66c8d27adceff Mon Sep 17 00:00:00 2001
From: Nathaniel McCallum <npmccal...@redhat.com>
Date: Tue, 24 May 2016 10:18:43 -0400
Subject: [PATCH] Migrate from #ifndef guards to #pragma once

Using a pragma instead of guards is easier to write, less error prone
and avoids name clashes (a source of very subtle bugs). This pragma
is supported on almost all compilers, including all the compilers we
care about: https://en.wikipedia.org/wiki/Pragma_once#Portability.
---
 asn1/ipa_asn1.h                                         | 5 +----
 client/ipa-client-common.h                              | 5 +----
 daemons/ipa-kdb/ipa_kdb_mspac_private.h                 | 6 +-----
 daemons/ipa-otpd/internal.h                             | 5 +----
 daemons/ipa-sam/ipa_sam.h                               | 5 +----
 daemons/ipa-slapi-plugins/common/util.h                 | 5 +----
 daemons/ipa-slapi-plugins/ipa-cldap/ipa_cldap.h         | 4 +---
 daemons/ipa-slapi-plugins/ipa-extdom-extop/ipa_extdom.h | 4 +---
 daemons/ipa-slapi-plugins/ipa-pwd-extop/syncreq.h       | 6 +-----
 daemons/ipa-slapi-plugins/ipa-sidgen/ipa_sidgen.h       | 4 +---
 daemons/ipa-slapi-plugins/ipa-winsync/ipa-winsync.h     | 5 +----
 util/ipa_krb5.h                                         | 4 +---
 util/ipa_mspac.h                                        | 5 +----
 util/ipa_pwd.h                                          | 5 +----
 14 files changed, 14 insertions(+), 54 deletions(-)

diff --git a/asn1/ipa_asn1.h b/asn1/ipa_asn1.h
index 6ffcc5cc81992966654c21e923a1f8883b32833b..089a5e5202082eacab370c97420b74dc236828f7 100644
--- a/asn1/ipa_asn1.h
+++ b/asn1/ipa_asn1.h
@@ -1,5 +1,4 @@
-#ifndef __IPA_ASN1_H_
-#define __IPA_ASN1_H_
+#pragma once
 
 #include "ipa_krb5.h"
 
@@ -72,5 +71,3 @@ bool ipaasn1_dec_getkt(void *buf, size_t len, bool *newkt,
  */
 bool ipaasn1_dec_getktreply(void *buf, size_t len,
                             int *kvno, struct keys_container *keys);
-
-#endif /* __IPA_ASN1_H_ */
diff --git a/client/ipa-client-common.h b/client/ipa-client-common.h
index e831c596c9d12c6205532442990fb5c89fbbfefc..d0db0637e3e9d09519fd43ef6851a6259a98142c 100644
--- a/client/ipa-client-common.h
+++ b/client/ipa-client-common.h
@@ -17,8 +17,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef __IPA_CLIENT_COMMON_H
-#define __IPA_CLIENT_COMMON_H
+#pragma once
 
 #include <libintl.h>
 #define _(STRING) gettext(STRING)
@@ -29,5 +28,3 @@
 #endif
 
 int init_gettext(void);
-
-#endif /* __IPA_CLIENT_COMMON_H */
diff --git a/daemons/ipa-kdb/ipa_kdb_mspac_private.h b/daemons/ipa-kdb/ipa_kdb_mspac_private.h
index be04071762316643d687e80986db0d7510e53ded..1052bb882e2a8a4dbbc1a6d3b166fca6e3a5e585 100644
--- a/daemons/ipa-kdb/ipa_kdb_mspac_private.h
+++ b/daemons/ipa-kdb/ipa_kdb_mspac_private.h
@@ -21,9 +21,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-
-#ifndef _IPA_KDB_MSPAC_PRIVATE_H_
-#define _IPA_KDB_MSPAC_PRIVATE_H_
+#pragma once
 
 struct ipadb_mspac {
     char *flat_domain_name;
@@ -53,5 +51,3 @@ struct ipadb_adtrusts {
 
 int string_to_sid(const char *str, struct dom_sid *sid);
 char *dom_sid_string(TALLOC_CTX *memctx, const struct dom_sid *dom_sid);
-
-#endif /* _IPA_KDB_MSPAC_PRIVATE_H_ */
diff --git a/daemons/ipa-otpd/internal.h b/daemons/ipa-otpd/internal.h
index 5ab4a7776cafe037c55e7610c39a7be263f4e3d9..43096edf06360a4a4789f6b3dc128072c7118d81 100644
--- a/daemons/ipa-otpd/internal.h
+++ b/daemons/ipa-otpd/internal.h
@@ -20,8 +20,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef INTERNAL_H_
-#define INTERNAL_H_
+#pragma once
 
 #include "krad.h"
 
@@ -149,5 +148,3 @@ const char *otpd_parse_radius(LDAP *ldp, LDAPMessage *entry,
 
 const char *otpd_parse_radius_username(LDAP *ldp, LDAPMessage *entry,
                                        struct otpd_queue_item *item);
-
-#endif /* INTERNAL_H_ */
diff --git a/daemons/ipa-sam/ipa_sam.h b/daemons/ipa-sam/ipa_sam.h
index 46e6ffe1a86ad9a452d3b4e802b2aa755e525fdc..9e20ffac59fb8ef3b330b32724dd13de564df3ff 100644
--- a/daemons/ipa-sam/ipa_sam.h
+++ b/daemons/ipa-sam/ipa_sam.h
@@ -18,11 +18,8 @@
 
 */
 
-#ifndef _PASSDB_PDB_IPA_H_
-#define _PASSDB_PDB_IPA_H_
+#pragma once
 
 /* The following definitions come from passdb/pdb_ipa.c  */
 
 NTSTATUS pdb_ipa_init(void);
-
-#endif /* _PASSDB_PDB_IPA_H_ */
diff --git a/daemons/ipa-slapi-plugins/common/util.h b/daemons/ipa-slapi-plugins/common/util.h
index eb3ddc0b9259877ac0301a114abf8c65f6b576a6..1eaf47facb717fe6a95d89fe02311205eabc3e96 100644
--- a/daemons/ipa-slapi-plugins/common/util.h
+++ b/daemons/ipa-slapi-plugins/common/util.h
@@ -34,8 +34,7 @@
  * All rights reserved.
  * END COPYRIGHT BLOCK **/
 
-#ifndef _SLAPI_PLUGINS_UTIL_H
-#define _SLAPI_PLUGINS_UTIL_H
+#pragma once
 
 #define EOK 0
 #define EFAIL -1
@@ -72,5 +71,3 @@
     slapi_log_error(SLAPI_LOG_TRACE, log_func, fmt, ##__VA_ARGS__)
 
 #define LOG_OOM() LOG_FATAL("Out of Memory!\n")
-
-#endif /* _SLAPI_PLUGINS_UTIL_H */
diff --git a/daemons/ipa-slapi-plugins/ipa-cldap/ipa_cldap.h b/daemons/ipa-slapi-plugins/ipa-cldap/ipa_cldap.h
index 5e963e3f8557d468d646e6343366921d17242e2d..a3ebfbfe29987cf061023afa3d2529b876beca00 100644
--- a/daemons/ipa-slapi-plugins/ipa-cldap/ipa_cldap.h
+++ b/daemons/ipa-slapi-plugins/ipa-cldap/ipa_cldap.h
@@ -37,8 +37,7 @@
  * All rights reserved.
  * END COPYRIGHT BLOCK **/
 
-#ifndef _IPA_CLDAP_H_
-#define _IPA_CLDAP_H_
+#pragma once
 
 #ifdef HAVE_CONFIG_H
 #  include <config.h>
@@ -108,4 +107,3 @@ int ipa_cldap_netlogon(struct ipa_cldap_ctx *ctx,
                        struct berval *reply);
 
 char *make_netbios_name(TALLOC_CTX *mem_ctx, const char *s);
-#endif /* _IPA_CLDAP_H_ */
diff --git a/daemons/ipa-slapi-plugins/ipa-extdom-extop/ipa_extdom.h b/daemons/ipa-slapi-plugins/ipa-extdom-extop/ipa_extdom.h
index a77711977186b702caafa2729dc13090c6031791..e121b8ba52e2531669ca88822a07a09e435a32b4 100644
--- a/daemons/ipa-slapi-plugins/ipa-extdom-extop/ipa_extdom.h
+++ b/daemons/ipa-slapi-plugins/ipa-extdom-extop/ipa_extdom.h
@@ -37,8 +37,7 @@
  * All rights reserved.
  * END COPYRIGHT BLOCK **/
 
-#ifndef _IPA_EXTDOM_H_
-#define _IPA_EXTDOM_H_
+#pragma once
 
 #ifdef HAVE_CONFIG_H
 #  include <config.h>
@@ -202,4 +201,3 @@ int pack_ber_group(enum response_types response_type,
                    gid_t gid, char **members, struct sss_nss_kv *kv_list,
                    struct berval **berval);
 void set_err_msg(struct extdom_req *req, const char *format, ...);
-#endif /* _IPA_EXTDOM_H_ */
diff --git a/daemons/ipa-slapi-plugins/ipa-pwd-extop/syncreq.h b/daemons/ipa-slapi-plugins/ipa-pwd-extop/syncreq.h
index 98a97c4c9f6d2e6bf74f97fc93053b3aebbc7821..2f6b50c3dc0ed7ad54de66cef0811cdf40e400ba 100644
--- a/daemons/ipa-slapi-plugins/ipa-pwd-extop/syncreq.h
+++ b/daemons/ipa-slapi-plugins/ipa-pwd-extop/syncreq.h
@@ -37,9 +37,7 @@
  * All rights reserved.
  * END COPYRIGHT BLOCK **/
 
-
-#ifndef SYNCREQ_H_
-#define SYNCREQ_H_
+#pragma once
 
 #include "../libotp/otp_config.h"
 #include <stdbool.h>
@@ -59,5 +57,3 @@ bool sync_request_present(Slapi_PBlock *pb);
 
 bool sync_request_handle(const struct otp_config *cfg, Slapi_PBlock *pb,
                          const char *user_dn);
-
-#endif /* SYNCREQ_H_ */
diff --git a/daemons/ipa-slapi-plugins/ipa-sidgen/ipa_sidgen.h b/daemons/ipa-slapi-plugins/ipa-sidgen/ipa_sidgen.h
index dec2a652464ec451ca7d32b9a82dd958202298e5..0feff7eec9999a76bf950b8b9fc9fa25b3a2fa88 100644
--- a/daemons/ipa-slapi-plugins/ipa-sidgen/ipa_sidgen.h
+++ b/daemons/ipa-slapi-plugins/ipa-sidgen/ipa_sidgen.h
@@ -37,8 +37,7 @@
  * All rights reserved.
  * END COPYRIGHT BLOCK **/
 
-#ifndef _IPA_SIDGEN_H_
-#define _IPA_SIDGEN_H_
+#pragma once
 
 #define OBJECTCLASS "objectclass"
 #define IPA_OBJECT "ipaobject"
@@ -105,4 +104,3 @@ int find_sid_for_ldap_entry(struct slapi_entry *entry,
                             const char *base_dn,
                             const char *dom_sid,
                             struct range_info **ranges);
-#endif /* _IPA_SIDGEN_H_ */
diff --git a/daemons/ipa-slapi-plugins/ipa-winsync/ipa-winsync.h b/daemons/ipa-slapi-plugins/ipa-winsync/ipa-winsync.h
index 664af32a703506ebe2ce5ea3abdd66466b63a8d5..a3200b00e0a2bc53b265a88decc3eb04938c5a7a 100644
--- a/daemons/ipa-slapi-plugins/ipa-winsync/ipa-winsync.h
+++ b/daemons/ipa-slapi-plugins/ipa-winsync/ipa-winsync.h
@@ -37,8 +37,7 @@
  * All rights reserved.
  * END COPYRIGHT BLOCK **/
 
-#ifndef IPA_WINSYNC_H
-#define IPA_WINSYNC_H
+#pragma once
 
 #ifdef HAVE_CONFIG_H
 #  include <config.h>
@@ -172,5 +171,3 @@ enum {
 #define IPA_WINSYNC_UPG_DEF_DN "cn=UPG Definition,cn=Definitions,cn=Managed Entries,cn=etc,%s"
 #define IPA_WINSYNC_UPG_DEF_ATTR "originfilter"
 #define IPA_WINSYNC_UPG_DEF_DISABLED "(objectclass=disable)"
-
-#endif /* IPA_WINSYNC_H */
diff --git a/util/ipa_krb5.h b/util/ipa_krb5.h
index c2a0dde2d24493132889548c6fb9d18f7a0b909e..60a8ced5d8a63532254b3703801d2aeb9ff45892 100644
--- a/util/ipa_krb5.h
+++ b/util/ipa_krb5.h
@@ -1,5 +1,4 @@
-#ifndef __IPA_KRB5_H_
-#define __IPA_KRB5_H_
+#pragma once
 
 #include <lber.h>
 #include <krb5/krb5.h>
@@ -83,4 +82,3 @@ int create_keys(krb5_context krbctx,
                 char **err_msg);
 
 int ipa_kstuples_to_string(krb5_key_salt_tuple *kst, int n_kst, char **str);
-#endif /* __IPA_KRB5_H_ */
diff --git a/util/ipa_mspac.h b/util/ipa_mspac.h
index 152317b182bec655b01132809ee5ecd8a1cf2e31..00a8f0d3131642721232037dd355c4e6baf0ca82 100644
--- a/util/ipa_mspac.h
+++ b/util/ipa_mspac.h
@@ -1,5 +1,4 @@
-#ifndef __IPA_MSPAC_H_
-#define __IPA_MSPAC_H_
+#pragma once
 
 char *ipa_mspac_well_known_sids[] = {
     "S-1-0",
@@ -28,5 +27,3 @@ char *ipa_mspac_well_known_sids[] = {
     "S-1-5-20",
     NULL
 };
-
-#endif /* __IPA_MSPAC_H_ */
diff --git a/util/ipa_pwd.h b/util/ipa_pwd.h
index bc07549cc864cc9a1ed0b58617b4624fbb9a864b..15041c4e5daa41698fba03128de14ac1d412aaf9 100644
--- a/util/ipa_pwd.h
+++ b/util/ipa_pwd.h
@@ -20,8 +20,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef _IPA_PWD_H_
-#define _IPA_PWD_H_
+#pragma once
 
 /* 90 days default pwd max lifetime */
 #define IPAPWD_DEFAULT_PWDLIFE (90 * 24 *3600)
@@ -75,5 +74,3 @@ int ipapwd_generate_new_history(char *password,
                                 int *new_pwd_hlen);
 
 int encode_nt_key(char *newPasswd, uint8_t *nt_key);
-
-#endif
-- 
2.8.3

-- 
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code

Reply via email to