projects
/
apps
/
madmutt.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
less horrible strncpy's
[apps/madmutt.git]
/
browser.c
diff --git
a/browser.c
b/browser.c
index
57cdbb1
..
53bab1a
100644
(file)
--- a/
browser.c
+++ b/
browser.c
@@
-12,7
+12,9
@@
#endif
#include <lib-lib/mem.h>
#endif
#include <lib-lib/mem.h>
+#include <lib-lib/str.h>
#include <lib-lib/macros.h>
#include <lib-lib/macros.h>
+#include <lib-lib/file.h>
#include "mutt.h"
#include "enter.h"
#include "mutt.h"
#include "enter.h"
@@
-34,7
+36,6
@@
#endif
#include "sidebar.h"
#endif
#include "sidebar.h"
-#include "lib/str.h"
#include "lib/list.h"
#include <stdlib.h>
#include "lib/list.h"
#include <stdlib.h>
@@
-154,7
+155,7
@@
static int link_is_dir (const char *folder, const char *path)
struct stat st;
char fullpath[_POSIX_PATH_MAX];
struct stat st;
char fullpath[_POSIX_PATH_MAX];
- mutt_concat_path
(fullpath, folder, path, sizeof (fullpath)
);
+ mutt_concat_path
(fullpath, sizeof(fullpath), folder, path
);
if (stat (fullpath, &st) == 0)
return (S_ISDIR (st.st_mode));
if (stat (fullpath, &st) == 0)
return (S_ISDIR (st.st_mode));
@@
-349,7
+350,7
@@
static const char *newsgroup_format_str (char *dest, size_t destlen, char op,
break;
case 'f':
break;
case 'f':
-
strncpy (fn, folder->ff->name, sizeof (fn) - 1
);
+
m_strcpy(fn, sizeof(fn), folder->ff->name
);
snprintf (tmp, sizeof (tmp), "%%%ss", fmt);
snprintf (dest, destlen, tmp, fn);
break;
snprintf (tmp, sizeof (tmp), "%%%ss", fmt);
snprintf (dest, destlen, tmp, fn);
break;
@@
-442,8
+443,8
@@
static void add_folder (MUTTMENU * m, struct browser_state *state,
}
(state->entry)[state->entrylen].new = new;
}
(state->entry)[state->entrylen].new = new;
- (state->entry)[state->entrylen].name =
str_dup
(name);
- (state->entry)[state->entrylen].desc =
str_dup
(name);
+ (state->entry)[state->entrylen].name =
m_strdup
(name);
+ (state->entry)[state->entrylen].desc =
m_strdup
(name);
#ifdef USE_IMAP
(state->entry)[state->entrylen].imap = 0;
#endif
#ifdef USE_IMAP
(state->entry)[state->entrylen].imap = 0;
#endif
@@
-484,7
+485,7
@@
static int examine_directory (MUTTMENU * menu, struct browser_state *state,
continue;
nntp_sync_sidebar (data);
if (prefix && *prefix && strncmp (prefix, data->group,
continue;
nntp_sync_sidebar (data);
if (prefix && *prefix && strncmp (prefix, data->group,
-
str_len
(prefix)) != 0)
+
m_strlen
(prefix)) != 0)
continue;
if (!((regexec (Mask.rx, data->group, 0, NULL, 0) == 0) ^ Mask.not))
continue;
continue;
if (!((regexec (Mask.rx, data->group, 0, NULL, 0) == 0) ^ Mask.not))
continue;
@@
-530,16
+531,16
@@
static int examine_directory (MUTTMENU * menu, struct browser_state *state,
init_state (state, menu);
while ((de = readdir (dp)) != NULL) {
init_state (state, menu);
while ((de = readdir (dp)) != NULL) {
- if (
str_cmp
(de->d_name, ".") == 0)
+ if (
m_strcmp
(de->d_name, ".") == 0)
continue; /* we don't need . */
if (prefix && *prefix
continue; /* we don't need . */
if (prefix && *prefix
- && str_ncmp (prefix, de->d_name,
str_len
(prefix)) != 0)
+ && str_ncmp (prefix, de->d_name,
m_strlen
(prefix)) != 0)
continue;
if (!((regexec (Mask.rx, de->d_name, 0, NULL, 0) == 0) ^ Mask.not))
continue;
continue;
if (!((regexec (Mask.rx, de->d_name, 0, NULL, 0) == 0) ^ Mask.not))
continue;
- mutt_concat_path
(buffer, d, de->d_name, sizeof (buffer)
);
+ mutt_concat_path
(buffer, sizeof(buffer), d, de->d_name
);
if (lstat (buffer, &s) == -1)
continue;
if (lstat (buffer, &s) == -1)
continue;
@@
-738,7
+739,7
@@
void _mutt_select_file (char *f, size_t flen, int flags, char ***files,
buffy = buffy && folder;
buffy = buffy && folder;
-
memset (&state, 0, sizeof (struct browser_state)
);
+
p_clear(&state, 1
);
if (!folder)
strfcpy (LastDirBackup, LastDir, sizeof (LastDirBackup));
if (!folder)
strfcpy (LastDirBackup, LastDir, sizeof (LastDirBackup));
@@
-775,13
+776,11
@@
void _mutt_select_file (char *f, size_t flen, int flags, char ***files,
}
else {
#endif
}
else {
#endif
- for (i =
str_len
(f) - 1; i > 0 && f[i] != '/'; i--);
+ for (i =
m_strlen
(f) - 1; i > 0 && f[i] != '/'; i--);
if (i > 0) {
if (f[0] == '/') {
if (i > 0) {
if (f[0] == '/') {
- if (i > sizeof (LastDir) - 1)
- i = sizeof (LastDir) - 1;
- strncpy (LastDir, f, i);
- LastDir[i] = 0;
+ i = MIN(sizeof(LastDir) - 1, i);
+ m_strcpy(LastDir, sizeof(LastDir), f);
}
else {
getcwd (LastDir, sizeof (LastDir));
}
else {
getcwd (LastDir, sizeof (LastDir));
@@
-851,7
+850,7
@@
void _mutt_select_file (char *f, size_t flen, int flags, char ***files,
init_menu (&state, menu, title, sizeof (title), buffy);
init_menu (&state, menu, title, sizeof (title), buffy);
-
FOREVER
{
+
for (;;)
{
switch (i = mutt_menuLoop (menu)) {
case OP_GENERIC_SELECT_ENTRY:
switch (i = mutt_menuLoop (menu)) {
case OP_GENERIC_SELECT_ENTRY:
@@
-879,8
+878,8
@@
void _mutt_select_file (char *f, size_t flen, int flags, char ***files,
}
#endif
else
}
#endif
else
- mutt_concat_path
(buf, LastDir, state.entry[menu->current].name
,
-
sizeof (buf)
);
+ mutt_concat_path
(buf, sizeof(buf), LastDir
,
+
state.entry[menu->current].name
);
if ((mx_get_magic (buf) <= 0)
#ifdef USE_IMAP
if ((mx_get_magic (buf) <= 0)
#ifdef USE_IMAP
@@
-892,8
+891,8
@@
void _mutt_select_file (char *f, size_t flen, int flags, char ***files,
/* save the old directory */
strfcpy (OldLastDir, LastDir, sizeof (OldLastDir));
/* save the old directory */
strfcpy (OldLastDir, LastDir, sizeof (OldLastDir));
- if (
str_cmp
(state.entry[menu->current].name, "..") == 0) {
- if (
str_cmp ("..", LastDir + str_len
(LastDir) - 2) == 0)
+ if (
m_strcmp
(state.entry[menu->current].name, "..") == 0) {
+ if (
m_strcmp("..", LastDir + m_strlen
(LastDir) - 2) == 0)
strcat (LastDir, "/.."); /* __STRCAT_CHECKED__ */
else {
char *p = strrchr (LastDir + 1, '/');
strcat (LastDir, "/.."); /* __STRCAT_CHECKED__ */
else {
char *p = strrchr (LastDir + 1, '/');
@@
-921,7
+920,7
@@
void _mutt_select_file (char *f, size_t flen, int flags, char ***files,
strfcpy (LastDir, state.entry[menu->current].name,
sizeof (LastDir));
/* tack on delimiter here */
strfcpy (LastDir, state.entry[menu->current].name,
sizeof (LastDir));
/* tack on delimiter here */
- n =
str_len
(LastDir) + 1;
+ n =
m_strlen
(LastDir) + 1;
/* special case "" needs no delimiter */
url_parse_ciss (&url, state.entry[menu->current].name);
/* special case "" needs no delimiter */
url_parse_ciss (&url, state.entry[menu->current].name);
@@
-936,8
+935,8
@@
void _mutt_select_file (char *f, size_t flen, int flags, char ***files,
else {
char tmp[_POSIX_PATH_MAX];
else {
char tmp[_POSIX_PATH_MAX];
- mutt_concat_path
(tmp, LastDir, state.entry[menu->current].name
,
-
sizeof (tmp)
);
+ mutt_concat_path
(tmp, sizeof(tmp), LastDir
,
+
state.entry[menu->current].name
);
strfcpy (LastDir, tmp, sizeof (LastDir));
}
strfcpy (LastDir, tmp, sizeof (LastDir));
}
@@
-986,7
+985,7
@@
void _mutt_select_file (char *f, size_t flen, int flags, char ***files,
strfcpy (f, state.entry[menu->current].name, flen);
#endif
else
strfcpy (f, state.entry[menu->current].name, flen);
#endif
else
- mutt_concat_path
(f, LastDir, state.entry[menu->current].name, flen
);
+ mutt_concat_path
(f, flen, LastDir, state.entry[menu->current].name
);
/* Fall through to OP_EXIT */
/* Fall through to OP_EXIT */
@@
-1004,9
+1003,9
@@
void _mutt_select_file (char *f, size_t flen, int flags, char ***files,
char full[_POSIX_PATH_MAX];
if (ff.tagged) {
char full[_POSIX_PATH_MAX];
if (ff.tagged) {
- mutt_concat_path
(full, LastDir, ff.name, sizeof (full)
);
+ mutt_concat_path
(full, sizeof(full), LastDir, ff.name
);
mutt_expand_path (full, sizeof (full));
mutt_expand_path (full, sizeof (full));
- tfiles[j++] =
str_dup
(full);
+ tfiles[j++] =
m_strdup
(full);
}
}
*files = tfiles;
}
}
*files = tfiles;
@@
-1015,7
+1014,7
@@
void _mutt_select_file (char *f, size_t flen, int flags, char ***files,
*numfiles = 1;
tfiles = p_new(char *, *numfiles);
mutt_expand_path (f, flen);
*numfiles = 1;
tfiles = p_new(char *, *numfiles);
mutt_expand_path (f, flen);
- tfiles[0] =
str_dup
(f);
+ tfiles[0] =
m_strdup
(f);
*files = tfiles;
}
}
*files = tfiles;
}
}
@@
-1129,7
+1128,7
@@
void _mutt_select_file (char *f, size_t flen, int flags, char ***files,
#endif
{
/* add '/' at the end of the directory name if not already there */
#endif
{
/* add '/' at the end of the directory name if not already there */
- int len =
str_len
(LastDir);
+ int len =
m_strlen
(LastDir);
if (len && LastDir[len - 1] != '/' && sizeof (buf) > len)
buf[len] = '/';
if (len && LastDir[len - 1] != '/' && sizeof (buf) > len)
buf[len] = '/';
@@
-1358,8
+1357,8
@@
void _mutt_select_file (char *f, size_t flen, int flags, char ***files,
BODY *b;
char buf[_POSIX_PATH_MAX];
BODY *b;
char buf[_POSIX_PATH_MAX];
- mutt_concat_path
(buf, LastDir, state.entry[menu->current].name
,
-
sizeof (buf)
);
+ mutt_concat_path
(buf, sizeof(buf), LastDir
,
+
state.entry[menu->current].name
);
b = mutt_make_file_attach (buf);
if (b != NULL) {
mutt_view_attachment (NULL, b, M_REGULAR, NULL, NULL, 0);
b = mutt_make_file_attach (buf);
if (b != NULL) {
mutt_view_attachment (NULL, b, M_REGULAR, NULL, NULL, 0);
@@
-1397,7
+1396,7
@@
void _mutt_select_file (char *f, size_t flen, int flags, char ***files,
mutt_FormatString (buffer, sizeof (buffer), NONULL(GroupFormat),
newsgroup_format_str, (unsigned long) &folder,
M_FORMAT_ARROWCURSOR);
mutt_FormatString (buffer, sizeof (buffer), NONULL(GroupFormat),
newsgroup_format_str, (unsigned long) &folder,
M_FORMAT_ARROWCURSOR);
- f->desc =
str_dup
(buffer); */
+ f->desc =
m_strdup
(buffer); */
if (menu->current + 1 < menu->max)
menu->current++;
menu->redraw = REDRAW_MOTION_RESYNCH;
if (menu->current + 1 < menu->max)
menu->current++;
menu->redraw = REDRAW_MOTION_RESYNCH;
@@
-1495,7
+1494,7
@@
void _mutt_select_file (char *f, size_t flen, int flags, char ***files,
mutt_FormatString (buffer, sizeof (buffer), NONULL(GroupFormat),
newsgroup_format_str, (unsigned long) &folder,
M_FORMAT_ARROWCURSOR);
mutt_FormatString (buffer, sizeof (buffer), NONULL(GroupFormat),
newsgroup_format_str, (unsigned long) &folder,
M_FORMAT_ARROWCURSOR);
- f->desc =
str_dup
(buffer);
+ f->desc =
m_strdup
(buffer);
} */
}
if (i == OP_BROWSER_SUBSCRIBE || i == OP_BROWSER_UNSUBSCRIBE) {
} */
}
if (i == OP_BROWSER_SUBSCRIBE || i == OP_BROWSER_UNSUBSCRIBE) {