wrappers applied

merge-experiment
Volker Birk 8 years ago
parent c5b0867368
commit 25cd0df373

@ -0,0 +1,347 @@
#! /bin/sh
# Wrapper for compilers which do not understand '-c -o'.
scriptversion=2012-10-14.11; # UTC
# Copyright (C) 1999-2014 Free Software Foundation, Inc.
# Written by Tom Tromey <tromey@cygnus.com>.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that contains a
# configuration script generated by Autoconf, you may include it under
# the same distribution terms that you use for the rest of that program.
# This file is maintained in Automake, please report
# bugs to <bug-automake@gnu.org> or send patches to
# <automake-patches@gnu.org>.
nl='
'
# We need space, tab and new line, in precisely that order. Quoting is
# there to prevent tools from complaining about whitespace usage.
IFS=" "" $nl"
file_conv=
# func_file_conv build_file lazy
# Convert a $build file to $host form and store it in $file
# Currently only supports Windows hosts. If the determined conversion
# type is listed in (the comma separated) LAZY, no conversion will
# take place.
func_file_conv ()
{
file=$1
case $file in
/ | /[!/]*) # absolute file, and not a UNC file
if test -z "$file_conv"; then
# lazily determine how to convert abs files
case `uname -s` in
MINGW*)
file_conv=mingw
;;
CYGWIN*)
file_conv=cygwin
;;
*)
file_conv=wine
;;
esac
fi
case $file_conv/,$2, in
*,$file_conv,*)
;;
mingw/*)
file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
;;
cygwin/*)
file=`cygpath -m "$file" || echo "$file"`
;;
wine/*)
file=`winepath -w "$file" || echo "$file"`
;;
esac
;;
esac
}
# func_cl_dashL linkdir
# Make cl look for libraries in LINKDIR
func_cl_dashL ()
{
func_file_conv "$1"
if test -z "$lib_path"; then
lib_path=$file
else
lib_path="$lib_path;$file"
fi
linker_opts="$linker_opts -LIBPATH:$file"
}
# func_cl_dashl library
# Do a library search-path lookup for cl
func_cl_dashl ()
{
lib=$1
found=no
save_IFS=$IFS
IFS=';'
for dir in $lib_path $LIB
do
IFS=$save_IFS
if $shared && test -f "$dir/$lib.dll.lib"; then
found=yes
lib=$dir/$lib.dll.lib
break
fi
if test -f "$dir/$lib.lib"; then
found=yes
lib=$dir/$lib.lib
break
fi
if test -f "$dir/lib$lib.a"; then
found=yes
lib=$dir/lib$lib.a
break
fi
done
IFS=$save_IFS
if test "$found" != yes; then
lib=$lib.lib
fi
}
# func_cl_wrapper cl arg...
# Adjust compile command to suit cl
func_cl_wrapper ()
{
# Assume a capable shell
lib_path=
shared=:
linker_opts=
for arg
do
if test -n "$eat"; then
eat=
else
case $1 in
-o)
# configure might choose to run compile as 'compile cc -o foo foo.c'.
eat=1
case $2 in
*.o | *.[oO][bB][jJ])
func_file_conv "$2"
set x "$@" -Fo"$file"
shift
;;
*)
func_file_conv "$2"
set x "$@" -Fe"$file"
shift
;;
esac
;;
-I)
eat=1
func_file_conv "$2" mingw
set x "$@" -I"$file"
shift
;;
-I*)
func_file_conv "${1#-I}" mingw
set x "$@" -I"$file"
shift
;;
-l)
eat=1
func_cl_dashl "$2"
set x "$@" "$lib"
shift
;;
-l*)
func_cl_dashl "${1#-l}"
set x "$@" "$lib"
shift
;;
-L)
eat=1
func_cl_dashL "$2"
;;
-L*)
func_cl_dashL "${1#-L}"
;;
-static)
shared=false
;;
-Wl,*)
arg=${1#-Wl,}
save_ifs="$IFS"; IFS=','
for flag in $arg; do
IFS="$save_ifs"
linker_opts="$linker_opts $flag"
done
IFS="$save_ifs"
;;
-Xlinker)
eat=1
linker_opts="$linker_opts $2"
;;
-*)
set x "$@" "$1"
shift
;;
*.cc | *.CC | *.cxx | *.CXX | *.[cC]++)
func_file_conv "$1"
set x "$@" -Tp"$file"
shift
;;
*.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO])
func_file_conv "$1" mingw
set x "$@" "$file"
shift
;;
*)
set x "$@" "$1"
shift
;;
esac
fi
shift
done
if test -n "$linker_opts"; then
linker_opts="-link$linker_opts"
fi
exec "$@" $linker_opts
exit 1
}
eat=
case $1 in
'')
echo "$0: No command. Try '$0 --help' for more information." 1>&2
exit 1;
;;
-h | --h*)
cat <<\EOF
Usage: compile [--help] [--version] PROGRAM [ARGS]
Wrapper for compilers which do not understand '-c -o'.
Remove '-o dest.o' from ARGS, run PROGRAM with the remaining
arguments, and rename the output as expected.
If you are trying to build a whole package this is not the
right script to run: please start by reading the file 'INSTALL'.
Report bugs to <bug-automake@gnu.org>.
EOF
exit $?
;;
-v | --v*)
echo "compile $scriptversion"
exit $?
;;
cl | *[/\\]cl | cl.exe | *[/\\]cl.exe )
func_cl_wrapper "$@" # Doesn't return...
;;
esac
ofile=
cfile=
for arg
do
if test -n "$eat"; then
eat=
else
case $1 in
-o)
# configure might choose to run compile as 'compile cc -o foo foo.c'.
# So we strip '-o arg' only if arg is an object.
eat=1
case $2 in
*.o | *.obj)
ofile=$2
;;
*)
set x "$@" -o "$2"
shift
;;
esac
;;
*.c)
cfile=$1
set x "$@" "$1"
shift
;;
*)
set x "$@" "$1"
shift
;;
esac
fi
shift
done
if test -z "$ofile" || test -z "$cfile"; then
# If no '-o' option was seen then we might have been invoked from a
# pattern rule where we don't need one. That is ok -- this is a
# normal compilation that the losing compiler can handle. If no
# '.c' file was seen then we are probably linking. That is also
# ok.
exec "$@"
fi
# Name of file we expect compiler to create.
cofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'`
# Create the lock directory.
# Note: use '[/\\:.-]' here to ensure that we don't use the same name
# that we are using for the .o file. Also, base the name on the expected
# object file name, since that is what matters with a parallel build.
lockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d
while true; do
if mkdir "$lockdir" >/dev/null 2>&1; then
break
fi
sleep 1
done
# FIXME: race condition here if user kills between mkdir and trap.
trap "rmdir '$lockdir'; exit 1" 1 2 15
# Run the compile.
"$@"
ret=$?
if test -f "$cofile"; then
test "$cofile" = "$ofile" || mv "$cofile" "$ofile"
elif test -f "${cofile}bj"; then
test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile"
fi
rmdir "$lockdir"
exit $ret
# Local Variables:
# mode: shell-script
# sh-indentation: 2
# eval: (add-hook 'write-file-hooks 'time-stamp)
# time-stamp-start: "scriptversion="
# time-stamp-format: "%:y-%02m-%02d.%02H"
# time-stamp-time-zone: "UTC"
# time-stamp-end: "; # UTC"
# End:

@ -60,6 +60,10 @@
# include <arpa/inet.h>
#endif
#include "wrappers.h"
int libetpan_deliver_sigpipe = 0;
uint16_t mail_get_service_port(const char * name, char * protocol)
{
struct servent * service;
@ -131,7 +135,9 @@ static int wait_connect(int s, int r, time_t timeout_seconds)
timeout.tv_usec = 0;
}
/* TODO: how to cancel this ? -> could be cancelled using a cancel fd */
r = select(s + 1, NULL, &fds, NULL, &timeout);
// answer: see man 3 signal
r = Select(s + 1, NULL, &fds, NULL, &timeout);
if (r <= 0) {
return -1;
}
@ -181,6 +187,7 @@ int mail_tcp_connect_with_local_address_timeout(const char * server, uint16_t po
#ifndef HAVE_IPV6
s = socket(PF_INET, SOCK_STREAM, 0);
if (s == -1)
goto err;
@ -212,7 +219,7 @@ int mail_tcp_connect_with_local_address_timeout(const char * server, uint16_t po
if (r == -1) {
goto close_socket;
}
r = connect(s, (struct sockaddr *) &sa, sizeof(struct sockaddr_in));
r = wait_connect(s, r, timeout);
if (r == -1) {
@ -244,13 +251,15 @@ int mail_tcp_connect_with_local_address_timeout(const char * server, uint16_t po
continue;
// Christopher Lyon Anderson - prevent SigPipe
// patch by fdik
if (!libetpan_deliver_sigpipe) {
#ifdef SO_NOSIGPIPE
int kOne = 1;
int err = setsockopt(s, SOL_SOCKET, SO_NOSIGPIPE, &kOne, sizeof(kOne));
if (err != 0)
continue;
#endif
}
if ((local_address != NULL) || (local_port != 0)) {
char local_port_str[6];
char * p_local_port_str;
@ -278,7 +287,7 @@ int mail_tcp_connect_with_local_address_timeout(const char * server, uint16_t po
if (r == -1) {
goto close_socket;
}
r = connect(s, ai->ai_addr, ai->ai_addrlen);
r = wait_connect(s, r, timeout);
@ -291,7 +300,7 @@ int mail_tcp_connect_with_local_address_timeout(const char * server, uint16_t po
#ifdef WIN32
closesocket(s);
#else
close(s);
Close(s);
#endif
continue;
} else {
@ -318,8 +327,9 @@ int mail_tcp_connect_with_local_address_timeout(const char * server, uint16_t po
#ifdef WIN32
closesocket(s);
#else
close(s);
Close(s);
#endif
err:
return -1;
}

@ -46,6 +46,8 @@
extern "C" {
#endif
extern int libetpan_deliver_sigpipe;
uint16_t mail_get_service_port(const char * name, char * protocol);
int mail_tcp_connect(const char * server, uint16_t port);
int mail_tcp_connect_timeout(const char * server, uint16_t port, time_t timeout);

@ -56,6 +56,9 @@
#ifdef HAVE_LIBLOCKFILE
#include <lockfile.h>
#endif
#include <errno.h>
#include "wrappers.h"
/* ********************************************************************** */
@ -233,7 +236,8 @@ static int lock_common(const char * filename, int fd, short locktype)
lock.l_type = locktype;
lock.l_whence = SEEK_SET;
r = fcntl(fd, F_SETLKW, &lock);
r = Fcntl(fd, F_SETLKW, &lock);
if (r < 0) {
/* WARNING POSIX lock could not be applied */
}
@ -252,11 +256,13 @@ static int lock_common(const char * filename, int fd, short locktype)
goto unlock;
}
fd2 = open(lockfilename, O_WRONLY|O_EXCL|O_CREAT, 0);
fd2 = Open(lockfilename, O_WRONLY|O_EXCL|O_CREAT, 0);
if (fd2 >= 0) {
/* defeat lock checking programs which test pid */
r = (int) write(fd2, "0", 2);
close(fd2);
// BUG: there are many errors not covered
r = (int) Write(fd2, "0", 2);
Close(fd2);
break;
}

@ -78,6 +78,10 @@
# define MUTEX_UNLOCK(x)
#endif
#include <errno.h>
#include "wrappers.h"
struct mailstream_cancel_internal {
#ifdef LIBETPAN_REENTRANT
MUTEX_KEY ms_lock;
@ -125,9 +129,9 @@ struct mailstream_cancel * mailstream_cancel_new(void)
return cancel;
close_pipe:
#ifndef WIN32
close(cancel->ms_fds[0]);
close(cancel->ms_fds[1]);
#ifndef WIN32
Close(cancel->ms_fds[0]);
Close(cancel->ms_fds[1]);
#else
CloseHandle(ms_internal->event);
#endif
@ -142,14 +146,15 @@ struct mailstream_cancel * mailstream_cancel_new(void)
void mailstream_cancel_free(struct mailstream_cancel * cancel)
{
struct mailstream_cancel_internal * ms_internal;
int r;
ms_internal = cancel->ms_internal;
MUTEX_DESTROY(&ms_internal->ms_lock);
#ifndef WIN32
close(cancel->ms_fds[0]);
close(cancel->ms_fds[1]);
Close(cancel->ms_fds[0]);
Close(cancel->ms_fds[1]);
#else
CloseHandle(ms_internal->event);
#endif
@ -174,7 +179,8 @@ void mailstream_cancel_notify(struct mailstream_cancel * cancel)
ch = 0;
#ifndef WIN32
r = (int) write(cancel->ms_fds[1], &ch, 1);
// BUG: many errors are not covered
r = (int) Write(cancel->ms_fds[1], &ch, 1);
#else
SetEvent(ms_internal->event);
#endif
@ -185,7 +191,8 @@ void mailstream_cancel_ack(struct mailstream_cancel * cancel)
#ifndef WIN32
char ch;
int r;
r = (int) read(cancel->ms_fds[0], &ch, 1);
// BUG: many errors are not covered
r = (int) Read(cancel->ms_fds[0], &ch, 1);
#endif
}

@ -58,11 +58,14 @@
#if defined(ANDROID) || defined(__ANDROID__)
#include <sys/select.h>
#endif
#include <errno.h>
#include "mailstream_cfstream.h"
#include "mailstream_compress.h"
#include "mailstream_cancel.h"
#include "wrappers.h"
#define LOG_FILE "libetpan-stream-debug.log"
LIBETPAN_EXPORT
@ -93,14 +96,14 @@ static inline void mailstream_logger_internal(mailstream_low * s, int is_stream_
mode_t old_mask; \
\
old_mask = umask(0077); \
f = fopen(LOG_FILE, "a"); \
f = Fopen(LOG_FILE, "a"); \
umask(old_mask); \
if (f != NULL) { \
size_t nmemb; \
maillock_write_lock(LOG_FILE, fileno(f)); \
nmemb = fwrite((buf), 1, (size), f); \
nmemb = Fwrite((buf), 1, (size), f); \
maillock_write_unlock(LOG_FILE, fileno(f)); \
fclose(f); \
Fclose(f); \
} \
} \
}
@ -120,14 +123,14 @@ static inline void mailstream_logger_internal(mailstream_low * s, int is_stream_
mode_t old_mask; \
\
old_mask = umask(0077); \
f = fopen(LOG_FILE, "a"); \
f = Fopen(LOG_FILE, "a"); \
umask(old_mask); \
if (f != NULL) { \
size_t nmemb; \
maillock_write_lock(LOG_FILE, fileno(f)); \
nmemb = fwrite((buf), 1, (size), f); \
nmemb = Fwrite((buf), 1, (size), f); \
maillock_write_unlock(LOG_FILE, fileno(f)); \
fclose(f); \
Fclose(f); \
} \
} \
}
@ -147,14 +150,14 @@ static inline void mailstream_logger_internal(mailstream_low * s, int is_stream_
mode_t old_mask; \
\
old_mask = umask(0077); \
f = fopen(LOG_FILE, "a"); \
f = Fopen(LOG_FILE, "a"); \
umask(old_mask); \
if (f != NULL) { \
size_t nmemb; \
maillock_write_lock(LOG_FILE, fileno(f)); \
nmemb = fputs((str), f); \
nmemb = Fputs((str), f); \
maillock_write_unlock(LOG_FILE, fileno(f)); \
fclose(f); \
Fclose(f); \
} \
} \
}
@ -464,7 +467,8 @@ int mailstream_low_wait_idle(mailstream_low * low, struct mailstream_cancel * id
delay.tv_sec = max_idle_delay;
delay.tv_usec = 0;
r = select(maxfd + 1, &readfds, NULL, NULL, &delay);
r = Select(maxfd + 1, &readfds, NULL, NULL, &delay);
if (r == 0) {
// timeout
return MAILSTREAM_IDLE_TIMEOUT;

@ -38,6 +38,7 @@
#endif
#include "mailstream_socket.h"
#include <errno.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
@ -65,10 +66,13 @@
# ifdef HAVE_SYS_SELECT_H
# include <sys/select.h>
# endif
# include <errno.h>
#endif
#include "mailstream_cancel.h"
#include "wrappers.h"
struct mailstream_socket_data {
int fd;
struct mailstream_cancel * cancel;
@ -140,7 +144,7 @@ static void socket_data_close(struct mailstream_socket_data * socket_data)
/* SEB */
closesocket(socket_data->fd);
#else
close(socket_data->fd);
Close(socket_data->fd);
#endif
socket_data->fd = -1;
}
@ -252,7 +256,8 @@ static ssize_t mailstream_low_socket_read(mailstream_low * s,
max_fd = socket_data->fd;
if (fd > max_fd)
max_fd = fd;
r = select(max_fd + 1, &fds_read, NULL,/* &fds_excp*/ NULL, &timeout);
r = Select(max_fd + 1, &fds_read, NULL,/* &fds_excp*/ NULL, &timeout);
if (r <= 0)
return -1;
@ -271,10 +276,10 @@ static ssize_t mailstream_low_socket_read(mailstream_low * s,
}
if (socket_data->use_read) {
return read(socket_data->fd, buf, count);
return Read(socket_data->fd, buf, count);
}
else {
return recv(socket_data->fd, buf, count, 0);
return Recv(socket_data->fd, buf, count, 0);
}
}
@ -334,7 +339,9 @@ static ssize_t mailstream_low_socket_write(mailstream_low * s,
max_fd = socket_data->fd;
if (fd > max_fd)
max_fd = fd;
r = select(max_fd + 1, &fds_read, &fds_write, /*&fds_excp */ NULL, &timeout);
r = Select(max_fd + 1, &fds_read, &fds_write, /*&fds_excp */ NULL, &timeout);
if (r <= 0)
return -1;
@ -351,8 +358,8 @@ static ssize_t mailstream_low_socket_write(mailstream_low * s,
if (!write_enabled)
return 0;
}
return send(socket_data->fd, buf, count, 0);
return Send(socket_data->fd, buf, count, 0);
}

@ -62,6 +62,7 @@
these 3 headers MUST be included before <sys/select.h>
to insure compatibility with Mac OS X (this is true for 10.2)
*/
#include <errno.h>
#ifdef WIN32
# include <win_etpan.h>
#else
@ -99,6 +100,8 @@
#include "mmapstring.h"
#include "mailstream_cancel.h"
#include "wrappers.h"
struct mailstream_ssl_context
{
int fd;
@ -322,14 +325,18 @@ static int wait_SSL_connect(int s, int want_read, time_t timeout_seconds)
timeout = mailstream_network_delay;
}
else {
timeout.tv_sec = timeout_seconds;
timeout.tv_sec = timeout_seconds;
timeout.tv_usec = 0;
}
/* TODO: how to cancel this ? */
// see man 3 signal
if (want_read)
r = select(s + 1, &fds, NULL, NULL, &timeout);
r = Select(s + 1, &fds, NULL, NULL, &timeout);
else
r = select(s + 1, NULL, &fds, NULL, &timeout);
r = Select(s + 1, NULL, &fds, NULL, &timeout);
if (r <= 0) {
return -1;
}
@ -658,7 +665,7 @@ static void ssl_data_close(struct mailstream_ssl_data * ssl_data)
#ifdef WIN32
closesocket(ssl_data->fd);
#else
close(ssl_data->fd);
Close(ssl_data->fd);
#endif
ssl_data->fd = -1;
}
@ -676,7 +683,7 @@ static void ssl_data_close(struct mailstream_ssl_data * ssl_data)
#ifdef WIN32
closesocket(ssl_data->fd);
#else
close(ssl_data->fd);
Close(ssl_data->fd);
#endif
ssl_data->fd = -1;
}
@ -816,7 +823,7 @@ static int wait_read(mailstream_low * s)
max_fd = ssl_data->fd;
if (fd > max_fd)
max_fd = fd;
r = select(max_fd + 1, &fds_read, NULL, NULL, &timeout);
r = Select(max_fd + 1, &fds_read, NULL, NULL, &timeout);
if (r <= 0)
return -1;
@ -962,7 +969,7 @@ static int wait_write(mailstream_low * s)
if (fd > max_fd)
max_fd = fd;
r = select(max_fd + 1, &fds_read, &fds_write, NULL, &timeout);
r = Select(max_fd + 1, &fds_read, &fds_write, NULL, &timeout);
if (r <= 0)
return -1;

@ -57,6 +57,8 @@
#endif
#endif
#include "wrappers.h"
#define MMAPSTRING_MAX(a, b) ((a) > (b) ? (a) : (b))
#define MMAPSTRING_MIN(a, b) ((a) < (b) ? (a) : (b))
@ -244,17 +246,17 @@ static MMAPString * mmap_string_realloc_file(MMAPString * string)
strcat(tmpfilename, tmpdir);
strcat(tmpfilename, "/libetpan-mmapstring-XXXXXX");
fd = mkstemp(tmpfilename);
fd = Mkstemp(tmpfilename);
if (fd == -1)
return NULL;
if (unlink(tmpfilename) == -1) {
close(fd);
r = Close(fd);
return NULL;
}
if (ftruncate(fd, string->allocated_len) == -1) {
close(fd);
if (Ftruncate(fd, string->allocated_len) == -1) {
Close(fd);
return NULL;
}
@ -262,7 +264,7 @@ static MMAPString * mmap_string_realloc_file(MMAPString * string)
MAP_SHARED, fd, 0);
if (data == (char *)MAP_FAILED) {
close(fd);
Close(fd);
return NULL;
}
@ -278,7 +280,7 @@ static MMAPString * mmap_string_realloc_file(MMAPString * string)
if (munmap(string->str, string->mmapped_size) == -1)
return NULL;
if (ftruncate(string->fd, string->allocated_len) == -1)
if (Ftruncate(string->fd, string->allocated_len) == -1)
return NULL;
data = mmap(NULL, string->allocated_len, PROT_WRITE | PROT_READ,
@ -414,7 +416,7 @@ mmap_string_free (MMAPString *string)
#ifndef MMAP_UNAVAILABLE
if (string->fd != -1) {
munmap(string->str, string->mmapped_size);
close(string->fd);
Close(string->fd);
}
else
#endif

@ -51,6 +51,9 @@
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include "wrappers.h"
static int imap_initialize(mailmessage * msg_info);
@ -517,17 +520,17 @@ static int imap_get_bodystructure(mailmessage * msg_info,
msg_info->msg_mime = get_ancestor(msg_info)->msg_mime;
get_ancestor(msg_info)->msg_mime = NULL;
f = fopen(filename, "w");
f = Fopen(filename, "w");
if (f == NULL) {
return MAIL_ERROR_FILE;
}
col = 0;
r = mailmime_write(f, &col, msg_info->msg_mime);
if (r != MAILIMF_NO_ERROR) {
fclose(f);
r = Fclose(f);
return MAIL_ERROR_FILE;
}
fclose(f);
Fclose(f);
}
return r;

@ -60,6 +60,9 @@
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include "wrappers.h"
static int get_flags(mailmessage * msg_info,
struct mail_flags ** result);
@ -185,7 +188,7 @@ static int prefetch(mailmessage * msg_info)
goto err;
}
fd = open(filename, O_RDONLY);
fd = Open(filename, O_RDONLY);
free(filename);
if (fd == -1) {
res = MAIL_ERROR_FILE;
@ -195,7 +198,7 @@ static int prefetch(mailmessage * msg_info)
mapping = mmap(NULL, msg_info->msg_size, PROT_READ, MAP_PRIVATE, fd, 0);
if (mapping == (char *)MAP_FAILED) {
res = MAIL_ERROR_FILE;
goto close;
goto Close;
}
data = malloc(sizeof(* data));
@ -216,8 +219,8 @@ static int prefetch(mailmessage * msg_info)
unmap:
munmap(mapping, msg_info->msg_size);
close:
close(fd);
Close:
Close(fd);
err:
return res;
}
@ -230,7 +233,7 @@ static void prefetch_free(struct generic_message_t * msg)
munmap(msg->msg_message, msg->msg_length);
msg->msg_message = NULL;
data = msg->msg_data;
close(data->fd);
Close(data->fd);
free(data);
}
}

@ -57,10 +57,13 @@
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#ifdef WIN32
# include "win_etpan.h"
#endif
#include "wrappers.h"
static int get_flags(mailmessage * msg_info,
struct mail_flags ** result);
@ -137,7 +140,7 @@ static int prefetch(mailmessage * msg_info)
goto err;
}
fd = open(filename, O_RDONLY);
fd = Open(filename, O_RDONLY);
free(filename);
if (fd == -1) {
res = MAIL_ERROR_FILE;
@ -147,7 +150,7 @@ static int prefetch(mailmessage * msg_info)
mapping = mmap(NULL, msg_info->msg_size, PROT_READ, MAP_PRIVATE, fd, 0);
if (mapping == (char *)MAP_FAILED) {
res = MAIL_ERROR_FILE;
goto close;
goto Close;
}
data = malloc(sizeof(* data));
@ -168,8 +171,8 @@ static int prefetch(mailmessage * msg_info)
unmap:
munmap(mapping, msg_info->msg_size);
close:
close(fd);
Close:
Close(fd);
err:
return res;
}
@ -182,7 +185,7 @@ static void prefetch_free(struct generic_message_t * msg)
munmap(msg->msg_message, msg->msg_length);
msg->msg_message = NULL;
data = msg->msg_data;
close(data->fd);
Close(data->fd);
free(data);
}
}

@ -52,6 +52,7 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <errno.h>
#include "mail.h"
#include "mail_cache_db.h"
@ -66,6 +67,8 @@
#include "mboxdriver_cached_message.h"
#include "libetpan-config.h"
#include "wrappers.h"
static int mboxdriver_cached_initialize(mailsession * session);
static void mboxdriver_cached_uninitialize(mailsession * session);
@ -487,15 +490,15 @@ static int write_max_uid_value(mailsession * session)
cached_data->mbox_flags_directory, MAIL_DIR_SEPARATOR,
cached_data->mbox_quoted_mb, MAIL_DIR_SEPARATOR, FILENAME_MAX_UID);
fd = creat(filename, S_IRUSR | S_IWUSR);
fd = Creat(filename, S_IRUSR | S_IWUSR);
if (fd < 0) {
res = MAIL_ERROR_FILE;
goto err;
}
f = fdopen(fd, "w");
f = Fdopen(fd, "w");
if (f == NULL) {
close(fd);
Close(fd);
res = MAIL_ERROR_FILE;
goto unlock;
}
@ -503,7 +506,7 @@ static int write_max_uid_value(mailsession * session)
mmapstr = mmap_string_new("");
if (mmapstr == NULL) {
res = MAIL_ERROR_MEMORY;
goto close;
goto Close;
}
r = mail_serialize_clear(mmapstr, &cur_token);
@ -519,22 +522,22 @@ static int write_max_uid_value(mailsession * session)
goto free_mmapstr;
}
r = (int) fwrite(mmapstr->str, 1, mmapstr->len, f);
r = (int) Fwrite(mmapstr->str, 1, mmapstr->len, f);
if ((size_t) r != mmapstr->len) {
res = MAIL_ERROR_FILE;
goto free_mmapstr;
}
mmap_string_free(mmapstr);
fclose(f);
Fclose(f);
mailmbox_write_unlock(folder);
return MAIL_NO_ERROR;
free_mmapstr:
mmap_string_free(mmapstr);
close:
fclose(f);
Close:
Fclose(f);
unlock:
mailmbox_read_unlock(folder);
err:
@ -562,18 +565,18 @@ static int read_max_uid_value(mailsession * session, uint32_t * result)
cached_data->mbox_flags_directory, MAIL_DIR_SEPARATOR,
cached_data->mbox_quoted_mb, MAIL_DIR_SEPARATOR, FILENAME_MAX_UID);
f = fopen(filename, "r");
f = Fopen(filename, "r");
if (f == NULL) {
res = MAIL_ERROR_FILE;
goto err;
}
read_size = fread(buf, 1, sizeof(uint32_t), f);
read_size = Fread(buf, 1, sizeof(uint32_t), f);
mmapstr = mmap_string_new_len(buf, read_size);
if (mmapstr == NULL) {
res = MAIL_ERROR_MEMORY;
goto close;
goto Close;
}
cur_token = 0;
@ -585,7 +588,7 @@ static int read_max_uid_value(mailsession * session, uint32_t * result)
}
mmap_string_free(mmapstr);
fclose(f);
Fclose(f);
* result = written_uid;
@ -593,8 +596,8 @@ static int read_max_uid_value(mailsession * session, uint32_t * result)
free_mmapstr:
mmap_string_free(mmapstr);
close:
fclose(f);
Close:
Fclose(f);
err:
return res;
}

@ -53,6 +53,7 @@
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "mailmh.h"
#include "maildriver_tools.h"
@ -60,6 +61,8 @@
#include "mhdriver_message.h"
#include "mailmessage.h"
#include "wrappers.h"
static int mhdriver_initialize(mailsession * session);
static void mhdriver_uninitialize(mailsession * session);
@ -745,21 +748,21 @@ static int mhdriver_copy_message(mailsession * session,
folder = mailmh_folder_find(mh->mh_main, mb);
if (folder == NULL) {
res = MAIL_ERROR_FOLDER_NOT_FOUND;
goto close;
goto Close;
}
r = mailmh_folder_add_message_file(folder, fd);
if (r != MAIL_NO_ERROR) {
res = MAIL_ERROR_COPY;
goto close;
goto Close;
}
close(fd);
Close(fd);
return MAIL_NO_ERROR;
close:
close(fd);
Close:
Close(fd);
err:
return res;
}

@ -53,6 +53,7 @@
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "mail.h"
#include "mail_cache_db.h"
@ -67,6 +68,8 @@
#include "mhdriver_tools.h"
#include "mailmessage.h"
#include "wrappers.h"
static int mhdriver_cached_initialize(mailsession * session);
static void mhdriver_cached_uninitialize(mailsession * session);
@ -255,15 +258,15 @@ static int write_max_uid_value(mailsession * session)
cached_data->mh_cache_directory,
cached_data->mh_quoted_mb, FILENAME_MAX_UID);
fd = creat(filename, S_IRUSR | S_IWUSR);
fd = Creat(filename, S_IRUSR | S_IWUSR);
if (fd < 0) {
res = MAIL_ERROR_FILE;
goto err;
}
f = fdopen(fd, "w");
f = Fdopen(fd, "w");
if (f == NULL) {
close(fd);
Close(fd);
res = MAIL_ERROR_FILE;
goto err;
}
@ -271,7 +274,7 @@ static int write_max_uid_value(mailsession * session)
mmapstr = mmap_string_new("");
if (mmapstr == NULL) {
res = MAIL_ERROR_MEMORY;
goto close;
goto Close;
}
r = mail_serialize_clear(mmapstr, &cur_token);
@ -287,21 +290,21 @@ static int write_max_uid_value(mailsession * session)
goto free_mmapstr;
}
r = (int) fwrite(mmapstr->str, 1, mmapstr->len, f);
(int) Fwrite(mmapstr->str, 1, mmapstr->len, f);
if ((size_t) r != mmapstr->len) {
res = MAIL_ERROR_FILE;
goto free_mmapstr;
}
mmap_string_free(mmapstr);
fclose(f);
Fclose(f);
return MAIL_NO_ERROR;
free_mmapstr:
mmap_string_free(mmapstr);
close:
fclose(f);
Close:
Fclose(f);
err:
return res;
}
@ -328,18 +331,19 @@ static int read_max_uid_value(mailsession * session)
cached_data->mh_cache_directory,
cached_data->mh_quoted_mb, FILENAME_MAX_UID);
f = fopen(filename, "r");
f = Fopen(filename, "r");
if (f == NULL) {
res = MAIL_ERROR_FILE;
goto err;
}
read_size = fread(buf, 1, sizeof(uint32_t), f);
// BUG: many errors are uncovered
read_size = Fread(buf, 1, sizeof(uint32_t), f);
mmapstr = mmap_string_new_len(buf, read_size);
if (mmapstr == NULL) {
res = MAIL_ERROR_MEMORY;
goto close;
goto Close;
}
cur_token = 0;
@ -351,7 +355,7 @@ static int read_max_uid_value(mailsession * session)
}
mmap_string_free(mmapstr);
fclose(f);
Fclose(f);
if (written_uid > ancestor_data->mh_cur_folder->fl_max_index)
ancestor_data->mh_cur_folder->fl_max_index = written_uid;
@ -360,8 +364,8 @@ static int read_max_uid_value(mailsession * session)
free_mmapstr:
mmap_string_free(mmapstr);
close:
fclose(f);
Close:
Fclose(f);
err:
return res;
}

@ -59,10 +59,13 @@
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#ifdef WIN32
# include "win_etpan.h"
#endif
#include "wrappers.h"
int mhdriver_mh_error_to_mail_error(int error)
{
switch (error) {
@ -153,7 +156,7 @@ int mhdriver_fetch_message(mailsession * session, uint32_t indx,
default:
res = mhdriver_mh_error_to_mail_error(r);
goto close;
goto Close;
}
r = mhdriver_fetch_size(session, indx, &size);
@ -164,13 +167,13 @@ int mhdriver_fetch_message(mailsession * session, uint32_t indx,
default:
res = mhdriver_mh_error_to_mail_error(r);
goto close;
goto Close;
}
str = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
if (str == (char *)MAP_FAILED) {
res = MAIL_ERROR_FETCH;
goto close;
goto Close;
}
/* strip "From " header for broken implementations */
@ -204,7 +207,7 @@ int mhdriver_fetch_message(mailsession * session, uint32_t indx,
}
munmap(str, size);
close(fd);
Close(fd);
* result = mmapstr->str;
* result_len = mmapstr->len;
@ -215,8 +218,8 @@ int mhdriver_fetch_message(mailsession * session, uint32_t indx,
mmap_string_free(mmapstr);
unmap:
munmap(str, size);
close:
close(fd);
Close:
Close(fd);
err:
return res;
}
@ -249,7 +252,7 @@ int mhdriver_fetch_header(mailsession * session, uint32_t indx,
default:
res = mhdriver_mh_error_to_mail_error(r);
goto close;
goto Close;
}
r = mhdriver_fetch_size(session, indx, &size);
@ -260,13 +263,13 @@ int mhdriver_fetch_header(mailsession * session, uint32_t indx,
default:
res = mhdriver_mh_error_to_mail_error(r);
goto close;
goto Close;
}
str = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
if (str == (char *)MAP_FAILED) {
res = MAIL_ERROR_FETCH;
goto close;
goto Close;
}
/* strip "From " header for broken implementations */
@ -311,7 +314,7 @@ int mhdriver_fetch_header(mailsession * session, uint32_t indx,
}
munmap(str, size);
close(fd);
Close(fd);
* result = mmapstr->str;
* result_len = mmapstr->len;
@ -322,8 +325,8 @@ int mhdriver_fetch_header(mailsession * session, uint32_t indx,
mmap_string_free(mmapstr);
unmap:
munmap(str, size);
close:
close(fd);
Close:
Close(fd);
err:
return res;
}

@ -53,6 +53,7 @@
#ifdef WIN32
# include "win_etpan.h"
#endif
#include <errno.h>
#include "mail_cache_db.h"