Lely core libraries 2.3.4
getopt.c File Reference

This file is part of the C11 and POSIX compatibility library. More...

#include "libc.h"
#include <lely/libc/unistd.h>
#include <assert.h>
#include <stddef.h>
#include <stdio.h>
Include dependency graph for getopt.c:

Go to the source code of this file.

Functions

int getopt (int argc, char *const argv[], const char *optstring)
 Parses options passed as arguments to main().
 

Variables

static int optoff
 The offset (in characters) of the next option with respect to the beginning of the current option argument.
 

Detailed Description

This file is part of the C11 and POSIX compatibility library.

See also
lely/libc/unistd.h
Author
J. S. Seldenthuis jseld.nosp@m.enth.nosp@m.uis@l.nosp@m.ely..nosp@m.com

Licensed 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.

Definition in file getopt.c.

Function Documentation

◆ getopt()

int getopt ( int  argc,
char *const  argv[],
const char *  optstring 
)

Parses options passed as arguments to main().

Parameters
argcthe argument count as passed to main().
argvthe argument array as passed to main().
optstringa pointer to a string of recognized option characters; if a character is followed by a colon, the option takes an argument. If the first character is a colon, this function returns ':' instead of '?' when a missing argument is detected and does not print a diagnostic message (regardless of the value of opterr).
Returns
the next option character, '?' if an unknown option character or missing argument is detected, or -1 if all the argument is not an option or all options are parsed.

Definition at line 46 of file getopt.c.