Some systems define fopen as a macro based on compiler settings.
The previous technique for reverting to the system fopen function
by merely undefining fopen is inadequate in this case. Instead,
avoid defining fopen entirely when compiling this source file.
Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil>
Tested-by: Mike Ralphson <mike@abacus.co.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
On Windows, if the resulting string fits exactly in the provided buffer,
but not the terminating NUL, then the return value of the system's
vsnprintf is the number of characters written. But since we had reserved
an extra byte anyway, we only need to make sure that the result is
NUL terminated.
Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
The recent commit f746bae84e uses utime() to
adjust time stamps of pack files. We better make sure that we have an
implementation of utime that sets time stamps in a fashion that works with
our stat() implementation. (The system's utime() implemenation has issues
with daylight saving time changes.)
Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
But we still have to cater for the strangeness that on Windows the size
parameter is the number of characters to write, not the size of the buffer.
Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
This cannot easily be an inline function because it uses isalpha(), which
is not yet declared when compat/mingw.c is parsed and so would give a
compiler warning.
Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
This was proposed by Dscho, and I agree it makes sense because it really
clutters git-compat-util.h.
This is the first step of this cleanup and is a mere code move.
Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
Some systems (namely HPUX and Windows) return -1 when maxsize in snprintf()
and in vsnprintf() is reached. So replace snprintf() and vsnprintf()
functions with our own ones that return correct value upon overflow.
[jc: verified that review comments by J6t have been incorporated, and
tightened the check to verify the resulting buffer contents, suggested
by Wayne Davison]
Signed-off-by: Michal Rokos <michal.rokos@nextsoft.cz>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This function tests whether there is a C: style prefix in the argument.
It returns always 0 on Unix.
With this functions a number of conditionals #ifdef __MINGW32__/#endif
can be removed.
The getcwd() replacement was simplified: It tried to elide the translation
of backslashes to slashes if there was no drive prfix, but this
optimization is wrong: We could be looking at an UNC path, which we also
want to translate.
Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
Some systems do not fail as expected when fread et al. are called on
a directory stream. Replace fopen on such systems which will fail
when the supplied path is a directory.
Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
qsort in Windows 2000 (and various other C libraries) is a Quicksort
with the usual O(n^2) worst case. Unfortunately, sorting Git trees
seems to get very close to that worst case quite often:
$ /git/gitbad runstatus
# On branch master
qsort, nmemb = 30842
done, 237838087 comparisons.
This patch adds a simplified version of the merge sort that is glibc's
qsort(3). As a merge sort, this needs a temporary array equal in size
to the array that is to be sorted, but has a worst-case performance of
O(n log n).
The complexity that was removed is:
* Doing direct stores for word-size and -aligned data.
* Falling back to quicksort if the allocation required to perform the
merge sort would likely push the machine into swap.
Even with these simplifications, this seems to outperform the Windows
qsort(3) implementation, even in Windows XP (where it is "fixed" and
doesn't trigger O(n^2) complexity on trees).
[jes: moved into compat/qsort.c, as per Johannes Sixt's suggestion]
[bcd: removed gcc-ism, thanks to Edgar Toernig. renamed make variable
per Junio's comment.]
Signed-off-by: Brian Downing <bdowning@lavos.net>
Signed-off-by: Steffen Prohaska <prohaska@zib.de>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
A lookup routine is extracted from env_unsetenv() because we will need it
for env_setenv(). The environment data is now released, too.
Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
The PATH related functions are now static and can lose the mingw_ prefix.
path_lookup() no longer looks in the current directory, and it will now
actually return NULL. Previously, it returned the input program name
as a fallback.
Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
The entries are now arranged in categories.
inet_ntop(), kill(), and openlog() are unused and, hence, removed.
Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
Although we made sure that in->it_interval is either zero or equal to
in->it_value, we were still using in->it_interval to compute the timeout,
which could be zero, for example, with git-log's --early-output flag.
Use in->it_value instead.
On the otherhand, we used in->it_value to check for a single-shot timer.
Use in->it_interval instead.
Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
After a program was determined to be a script (which implies that it did
not have a file extension), then the interpreter is looked up. This change
makes sure that we will only find .exe files when we are looking for an
interpreter. Otherwise, we could find a directory 'perl' that is somewhere
earlier in the path than 'perl.exe'.
Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
The problem with Windows's own implementation is that it tries to be
clever when a console program is invoked from a GUI application: In this
case it sometimes automatically allocates a new console windows. As a
consequence, the IO channels of the spawned program are directed to the
console, but the invoking application listens on channels that are now
directed to nowhere.
In this implementation we use the lowlevel facilities of CreateProcess(),
which offers a flag to tell the system not to open a console. As a side
effect, only stdin, stdout, and stderr channels will be accessible from
C programs that are spawned. Other channels (file handles, pipe handles,
etc.) are still inherited by the spawned program, but it doesn't get
enough information to access them.
Johannes Schindelin integrated path quoting and unified the various
*execv* and *spawnv* helpers.
Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
By doing so the only external user of the path handling and functions
is removed, and these functions can be made static.
Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
We want to make them static later, and we need them in the proper order
for this. There is otherwise no code change.
Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
gethostbyname() is the first function that calls into the Winsock library,
and it is wrapped only to initialize the library.
socket() is wrapped for two reasons:
- Windows's socket() creates things that are like low-level file handles,
and they must be converted into file descriptors first.
- And these handles cannot be used with plain ReadFile()/WriteFile()
because they are opened for "overlapped IO". We have to use WSASocket()
to create non-overlapped IO sockets.
connect() must be wrapped because Windows's connect() expects the low-level
sockets, not file descriptors, and we must first unwrap the file descriptor
before we can pass it on to Windows's connect().
Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
There were some references to the progress indicator, where this
implementation originally appeared.
Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
In general, we don't add unnecessary braces. But in this case
gcc warns about them. So this commit adds a few braces.
The commit suppresses warnings about unitialized variables
by initializing them to NULL.
The change of bcmp_translate()'s parameter declaration is needed
to avoid warnings about "discards qualifiers from pointer target
type".
[sp: split original commit; more detailed commit message. ]
Signed-off-by: Dmitry Kakurin <Dmitry.Kakurin@gmail.com>
Signed-off-by: Steffen Prohaska <prohaska@zib.de>
This emulation of poll() is by far not general. It assumes that the
fds that are to be waited for are connected to pipes. The pipes are
polled in a loop until data becomes available in at least one of them.
If only a single fd is waited for, the implementation actually does
not wait at all, but assumes that a subsequent read() will block.
In order to not burn CPU time, it is yielded to other processes before
the next round in the poll loop using Sleep(0). Note that any sleep
timeout greater than zero will reduce the efficiency by a magnitude.
Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
We want to get rid of spawn-pipe.*, but these functions will be needed.
On the way, the function signature was changed to avoid warnings about
incompatible pointer types when the argument is the global variable
"environ".
The wrapper does two things:
- Requests to open /dev/null are redirected to open the nul pseudo file.
- A request to open a file that currently exists as a directory, then
Windows's open fails with EACCES; this is changed to EISDIR.
Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
Quite a lot of stuff has accumulated or is now obsolete. The stubs of
POSIX functions that are not implemented or that always fail are now
implemented as inline functions so that they exist in only one place.
Windows's struct stat does not have a st_blocks member. Since we already
have our own stat/lstat/fstat implementations, we can just as well use
a customized struct stat. This patch introduces just that, and also fills
in the st_blocks member. On the other hand, we don't provide members that
are never used.
Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
getpwuid() is kept as simple as possible so that no errors are generated.
Since the information that it returns is not very useful, users are still
required to set up user.name and user.email configuration.
All uses of getpwuid() are like getpwuid(getuid()), hence, the return value
of getpwuid() is irrelevant. getpwnam() is only used to resolve '~' and
'~username' paths, which is an idiom not known on Windows, hence, we
don't implement it, either.
Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
* maint:
Remove a couple of duplicated include
grep with unmerged index
git-daemon: fix remote port number in log entry
git-svn: t9114: verify merge commit message in test
git-svn: fix dcommit clobbering when committing a series of diffs
Since these functions are MinGW-specific, they better belong into this
compatibility file. They will be needed there in a follow-up change that
reimplements execvp().