LibC: Implement getopt_long{,_only}

Few ports attempt to use this so lets add them :D
This commit is contained in:
2025-08-11 18:36:46 +03:00
parent c9355ad94a
commit fde4d4662e
6 changed files with 239 additions and 89 deletions

View File

@@ -0,0 +1,15 @@
#ifndef _BITS_GETOPT_H
#define _BITS_GETOPT_H 1
#include <sys/cdefs.h>
__BEGIN_DECLS
int getopt(int argc, char* const argv[], const char* optstring);
extern char* optarg;
extern int opterr, optind, optopt;
__END_DECLS
#endif

View File

@@ -0,0 +1,27 @@
#ifndef _GETOPT_H
#define _GETOPT_H 1
#include <sys/cdefs.h>
__BEGIN_DECLS
#include <bits/getopt.h>
struct option
{
const char* name;
int has_arg;
int* flag;
int val;
};
#define no_argument 0
#define required_argument 1
#define optional_argument 2
int getopt_long(int argc, char* argv[], const char* optstring, const struct option* longopts, int* longindex);
int getopt_long_only(int argc, char* argv[], const char* optstring, const struct option* longopts, int* longindex);
__END_DECLS
#endif

View File

@@ -124,6 +124,8 @@ __BEGIN_DECLS
#define __need_useconds_t
#include <sys/types.h>
#include <bits/getopt.h>
enum
{
_CS_PATH = 1,
@@ -547,7 +549,6 @@ long gethostid(void);
int gethostname(char* name, size_t namelen);
char* getlogin(void);
int getlogin_r(char* name, size_t namesize);
int getopt(int argc, char* const argv[], const char* optstring);
pid_t getpgid(pid_t pid);
pid_t getpgrp(void);
pid_t getpid(void);
@@ -600,9 +601,6 @@ int chroot(const char* path);
int getpagesize(void);
char* getpass(const char* prompt);
extern char* optarg;
extern int opterr, optind, optopt;
long syscall(long syscall, ...);
__END_DECLS