Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Ensured C99/POSIX.1b compliance.

  • Loading branch information...
commit 759cd2394794ea871d3e763c9318b54679e1d53c 1 parent 2f32e85
@Nadrin authored
Showing with 27 additions and 13 deletions.
  1. +3 −2 Makefile
  2. +6 −5 include/libxlsh.h
  3. +8 −0 src/libxlsh.c
  4. +10 −6 src/xlsh.c
View
5 Makefile
@@ -18,8 +18,9 @@ INSTALL_DATA = $(INSTALL) -m 644
INSTALL_PROGRAM = $(INSTALL)
INSTALL_PROGRAM_STRIP = $(INSTALL) -s
-CFLAGS += -g -Wall
-ALL_CFLAGS = -I./include $(CFLAGS)
+CMACROS = -D_POSIX_C_SOURCE=199309L -D_BSD_SOURCE
+CFLAGS += -g -std=c99 -pedantic -Wall -Wcast-qual -Wpointer-arith -fstrict-aliasing
+ALL_CFLAGS = -I./include $(CFLAGS) $(CMACROS)
.SUFFIXES:
.SUFFIXES: .o
View
11 include/libxlsh.h
@@ -22,10 +22,11 @@
#define XLSH_OVERWRITE 0x01
#define XLSH_DETACH 0x02
-void libxlsh_proc_sigmask(void);
-pid_t libxlsh_proc_exec(const char* cmdline, int flags);
-pid_t libxlsh_pid_read(const char* filename);
-int libxlsh_pid_lock(const char* filename, pid_t pid, int flags);
-int libxlsh_file_read(const char* filename, char** buffer, size_t* bufsize);
+size_t libxlsh_strnlen(const char* s, size_t maxlen);
+void libxlsh_proc_sigmask(void);
+pid_t libxlsh_proc_exec(const char* cmdline, int flags);
+pid_t libxlsh_pid_read(const char* filename);
+int libxlsh_pid_lock(const char* filename, pid_t pid, int flags);
+int libxlsh_file_read(const char* filename, char** buffer, size_t* bufsize);
#endif
View
8 src/libxlsh.c
@@ -18,6 +18,14 @@
static sigset_t xlsh_default_sigmask;
+// Compatibility functions
+size_t libxlsh_strnlen(const char* s, size_t maxlen)
+{
+ size_t len = 0;
+ while(*s++ && ++len < maxlen);
+ return len;
+}
+
// Process functions
void libxlsh_proc_sigmask(void)
{
View
16 src/xlsh.c
@@ -210,7 +210,7 @@ char* xlsh_session_getpass(char* buffer, size_t bufsize)
fflush(stdin);
fgets(buffer, bufsize, stdin);
- pass_len = strnlen(buffer, bufsize-1);
+ pass_len = libxlsh_strnlen(buffer, bufsize-1);
if(buffer[pass_len-1] == '\n')
buffer[pass_len-1] = 0;
@@ -226,7 +226,7 @@ char* xlsh_session_getstring(char* buffer, size_t bufsize)
fflush(stdin);
fgets(buffer, bufsize, stdin);
- string_len = strnlen(buffer, bufsize-1);
+ string_len = libxlsh_strnlen(buffer, bufsize-1);
if(buffer[string_len-1] == '\n')
buffer[string_len-1] = 0;
@@ -502,13 +502,13 @@ static char* xlsh_cmd_readline(const char* prompt)
static char* xlsh_cmd_match_command(const char* text, int state)
{
static size_t index, len;
- char* cmd_name;
+ const char* cmd_name;
if(!state) {
index = 0;
len = strlen(text);
}
- while((cmd_name = (char*)xlsh_commands[index++].name)) {
+ while((cmd_name = xlsh_commands[index++].name)) {
if(strncmp(cmd_name, text, len) == 0)
return strdup(cmd_name);
}
@@ -542,12 +542,16 @@ static char* xlsh_cmd_match_user(const char* text, int state)
static char** xlsh_cmd_complete(const char* text, int start, int end)
{
+ union { const char* cc; char* c; } const_cast;
+
+ const_cast.cc = text;
rl_attempted_completion_over = 1;
+
if(start == 0)
- return rl_completion_matches((char*)text,
+ return rl_completion_matches(const_cast.c,
xlsh_cmd_match_command);
else
- return rl_completion_matches((char*)text,
+ return rl_completion_matches(const_cast.c,
xlsh_cmd_match_user);
}
Please sign in to comment.
Something went wrong with that request. Please try again.