You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2020/11/18 12:55:09 UTC

[GitHub] [incubator-nuttx] patacongo commented on a change in pull request #2326: libc: Enhance getopt function

patacongo commented on a change in pull request #2326:
URL: https://github.com/apache/incubator-nuttx/pull/2326#discussion_r526064104



##########
File path: include/getopt.h
##########
@@ -0,0 +1,154 @@
+/****************************************************************************
+ * include/getopt.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_GETOPT_H
+#define __INCLUDE_GETOPT_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <unistd.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Names for the values of the `has_arg' field of `struct option'. */
+
+#define no_argument             0
+#define required_argument       1
+#define optional_argument       2
+
+#define NO_ARG                  no_argument
+#define REQUIRED_ARG            required_argument
+#define OPTIONAL_ARG            optional_argument
+
+/* The GETOPT_DATA_INITIALIZER macro is used to initialize a statically-
+ * allocated variable of type struct getopt_data.
+ */
+
+#define GETOPT_DATA_INITIALIZER {0, 0, 1, 0, 0, 0, 0}
+
+/****************************************************************************
+ * Public Type Definitions
+ ****************************************************************************/
+
+#undef EXTERN
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+/* Describe the long-named options requested by the application.
+ * The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
+ * of `struct option' terminated by an element containing a name which is
+ * zero.
+ *
+ * The field `has_arg' is:
+ * no_argument       (or 0) if the option does not take an argument,
+ * required_argument (or 1) if the option requires an argument,
+ * optional_argument (or 2) if the option takes an optional argument.
+ *
+ * If the field `flag' is not NULL, it points to a variable that is set
+ * to the value given in the field `val' when the option is found, but
+ * left unchanged if the option is not found.
+ *
+ * To have a long-named option do something other than set an `int' to
+ * a compiled-in constant, such as set a value from `optarg', set the
+ * option's `flag' field to zero and its `val' field to a nonzero
+ * value (the equivalent single-letter option character, if there is
+ * one).  For long options that have a zero `flag' field, `getopt'
+ * returns the contents of the `val' field.
+ */
+
+struct option
+{

Review comment:
       Coding standard requires that structure names end with _s




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org