diff --git a/disk.c b/disk.c index f326031..672dccb 100644 --- a/disk.c +++ b/disk.c @@ -997,7 +997,7 @@ FsVolumeInfo(char *fpath) while ((e = getmntent(fdfs))) { - if (strncmp(fpath, e->mnt_dir, strlen(fpath)) == 0) + if (str_startswith(e->mnt_dir, fpath)) { strcpy(info.type, e->mnt_type); strcpy(info.name, e->mnt_fsname); diff --git a/proto.h b/proto.h index dc2189b..1d50e11 100644 --- a/proto.h +++ b/proto.h @@ -117,6 +117,7 @@ void unimpl(char *format, ...); void hexdump(unsigned char *p, unsigned int len); char *next_arg(char *src, char needle); void toupper_str(char *p); +BOOL str_startswith(const char *s, const char *prefix); char *l_to_a(long N, int base); int load_licence(unsigned char **data); void save_licence(unsigned char *data, int length); diff --git a/rdesktop.c b/rdesktop.c index 33a3a1c..57796de 100644 --- a/rdesktop.c +++ b/rdesktop.c @@ -605,17 +605,17 @@ main(int argc, char *argv[]) break; case 'x': - if (strncmp("modem", optarg, 1) == 0) + if (str_startswith(optarg, "m")) /* modem */ { g_rdp5_performanceflags = RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | RDP5_NO_MENUANIMATIONS | RDP5_NO_THEMING; } - else if (strncmp("broadband", optarg, 1) == 0) + else if (str_startswith(optarg, "b")) /* broadband */ { g_rdp5_performanceflags = RDP5_NO_WALLPAPER; } - else if (strncmp("lan", optarg, 1) == 0) + else if (str_startswith(optarg, "l")) /* lan */ { g_rdp5_performanceflags = RDP5_DISABLE_NOTHING; } @@ -631,7 +631,7 @@ main(int argc, char *argv[]) case 'r': - if (strncmp("sound", optarg, 5) == 0) + if (str_startswith(optarg, "sound")) { optarg += 5; @@ -640,17 +640,17 @@ main(int argc, char *argv[]) *optarg++; while ((p = next_arg(optarg, ','))) { - if (strncmp("remote", optarg, 6) == 0) + if (str_startswith(optarg, "remote")) flags |= RDP_LOGON_LEAVE_AUDIO; - if (strncmp("local", optarg, 5) == 0) + if (str_startswith(optarg, "local")) #ifdef WITH_RDPSND g_rdpsnd = True; #else warning("Not compiled with sound support\n"); #endif - if (strncmp("off", optarg, 3) == 0) + if (str_startswith(optarg, "off")) #ifdef WITH_RDPSND g_rdpsnd = False; #else @@ -669,24 +669,24 @@ main(int argc, char *argv[]) #endif } } - else if (strncmp("disk", optarg, 4) == 0) + else if (str_startswith(optarg, "disk")) { /* -r disk:h:=/mnt/floppy */ disk_enum_devices(&g_num_devices, optarg + 4); } - else if (strncmp("comport", optarg, 7) == 0) + else if (str_startswith(optarg, "comport")) { serial_enum_devices(&g_num_devices, optarg + 7); } - else if (strncmp("lptport", optarg, 7) == 0) + else if (str_startswith(optarg, "lptport")) { parallel_enum_devices(&g_num_devices, optarg + 7); } - else if (strncmp("printer", optarg, 7) == 0) + else if (str_startswith(optarg, "printer")) { printer_enum_devices(&g_num_devices, optarg + 7); } - else if (strncmp("clientname", optarg, 7) == 0) + else if (str_startswith(optarg, "clientname")) { g_rdpdr_clientname = xmalloc(strlen(optarg + 11) + 1); strcpy(g_rdpdr_clientname, optarg + 11); @@ -1170,6 +1170,13 @@ toupper_str(char *p) } +BOOL +str_startswith(const char *s, const char *prefix) +{ + return (strncmp(s, prefix, strlen(prefix)) == 0); +} + + /* not all clibs got ltoa */ #define LTOA_BUFSIZE (sizeof(long) * 8 + 1) diff --git a/xkeymap.c b/xkeymap.c index ab24671..5d1872b 100644 --- a/xkeymap.c +++ b/xkeymap.c @@ -311,7 +311,7 @@ xkeymap_read(char *mapname) } /* Include */ - if (strncmp(line, "include ", sizeof("include ") - 1) == 0) + if (str_startswith(line, "include ")) { if (!xkeymap_read(line + sizeof("include ") - 1)) return False; @@ -319,7 +319,7 @@ xkeymap_read(char *mapname) } /* map */ - if (strncmp(line, "map ", sizeof("map ") - 1) == 0) + if (str_startswith(line, "map ")) { g_keylayout = strtol(line + sizeof("map ") - 1, NULL, 16); DEBUG_KBD(("Keylayout 0x%x\n", g_keylayout)); @@ -327,7 +327,7 @@ xkeymap_read(char *mapname) } /* compose */ - if (strncmp(line, "enable_compose", sizeof("enable_compose") - 1) == 0) + if (str_startswith(line, "enable_compose")) { DEBUG_KBD(("Enabling compose handling\n")); g_enable_compose = True; @@ -335,14 +335,14 @@ xkeymap_read(char *mapname) } /* sequence */ - if (strncmp(line, "sequence", sizeof("sequence") - 1) == 0) + if (str_startswith(line, "sequence")) { add_sequence(line + sizeof("sequence") - 1, mapname); continue; } /* keyboard_type */ - if (strncmp(line, "keyboard_type ", sizeof("keyboard_type ") - 1) == 0) + if (str_startswith(line, "keyboard_type ")) { g_keyboard_type = strtol(line + sizeof("keyboard_type ") - 1, NULL, 16); DEBUG_KBD(("keyboard_type 0x%x\n", g_keyboard_type)); @@ -350,7 +350,7 @@ xkeymap_read(char *mapname) } /* keyboard_subtype */ - if (strncmp(line, "keyboard_subtype ", sizeof("keyboard_subtype ") - 1) == 0) + if (str_startswith(line, "keyboard_subtype ")) { g_keyboard_subtype = strtol(line + sizeof("keyboard_subtype ") - 1, NULL, 16); @@ -359,8 +359,7 @@ xkeymap_read(char *mapname) } /* keyboard_functionkeys */ - if (strncmp(line, "keyboard_functionkeys ", sizeof("keyboard_functionkeys ") - 1) == - 0) + if (str_startswith(line, "keyboard_functionkeys ")) { g_keyboard_functionkeys = strtol(line + sizeof("keyboard_functionkeys ") - 1, NULL, 16);