Making source C99 compliant

This commit is contained in:
Martin Dvorak 2013-12-26 00:58:52 +01:00
parent 7e91f2bcd3
commit eef3a67183
5 changed files with 22 additions and 5 deletions

View file

@ -2,7 +2,6 @@
rm -vf *.*~
# copy hstr/ source code to a work directory and run this script to create DEB package
cd ..
bzr commit -m "Sync."
bzr builddeb -- -us -uc

View file

@ -59,7 +59,8 @@ int hashset_put(HashSet * hs, const char *key, void *value) {
return 0;
}
newNode->key = strdup( key );
newNode->key = malloc(strlen(key)+1);
strcpy(newNode->key, key);
newNode->value = value;
newNode->next = hs->lists[ listNum ];
hs->lists[ listNum ] = newNode;

View file

@ -63,11 +63,10 @@ static bool terminalHasColors=FALSE;
static char screenLine[1000];
int print_prompt(WINDOW *win) {
char hostname[128];
char *hostname = get_hostname();
char *user = getenv(ENV_VAR_USER);
int xoffset = 1;
gethostname(hostname, sizeof hostname);
mvwprintw(win, xoffset, Y_OFFSET_PROMPT, "%s@%s$ ", user, hostname);
refresh();

View file

@ -10,6 +10,8 @@
#include "include/hstr_utils.h"
#define DEFAULT_COMMAND "pwd"
#define HOSTNAME_BUFFER 100
#define PROC_HOSTNAME "/proc/sys/kernel/hostname"
void tiocsti() {
char buf[] = DEFAULT_COMMAND;
@ -43,5 +45,19 @@ void reverse_char_pointer_array(char **array, unsigned length) {
}
}
char *get_hostname()
{
char *b=malloc(HOSTNAME_BUFFER);
if(access( PROC_HOSTNAME, F_OK ) != -1) {
FILE *f = fopen(PROC_HOSTNAME, "r");
b=fgets(b, HOSTNAME_BUFFER, f);
fclose(f);
if(b) {
b[strlen(b)-1]=0;
return b;
}
}
strcpy(b,"localhost");
return b;
}

View file

@ -15,6 +15,7 @@
#include <string.h>
#include <stdio.h>
#include <stdbool.h>
#include <unistd.h>
#define MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)>(b))?(a):(b))
@ -22,5 +23,6 @@
void tiocsti();
void fill_terminal_input(char* cmd, bool padding);
void reverse_char_pointer_array(char **array, unsigned length);
char *get_hostname();
#endif