[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: CVS problem with ssh
From: |
Richard M. Stallman |
Subject: |
Re: CVS problem with ssh |
Date: |
Thu, 07 Jul 2005 01:37:10 -0400 |
I wrote the code, checking the specs, and got it to compile correctly.
I don't have any easy way to test it--Emacs is not well suited to that
purpose. Could you test it?
/* The idea of this module is to help programs cope with output
streams that have become nonblocking.
To use it, simply make these definitions in your other files:
#define printf subst_printf
#define fprintf subst_fprintf
#define vprintf subst_vprintf
#define vfprintf subst_vfprintf
#undef putchar
#define putchar subst_putchar
#undef putc
#define putc subst_putc
#define fputc subst_fputc
#define puts subst_puts
#define fputs subst_fputs
#define fwrite subst_fwrite
and link with this module. */
#include <stddef.h>
#include <stdio.h>
#include <stdarg.h>
#include <sys/select.h>
int
subst_printf (const char *format, ...)
{
int out_count;
char *buffer;
int size = 1000;
while (1)
{
va_list argptr;
buffer = (char *) malloc (size);
/* Format it into BUFFER, as much as fits. */
va_start (argptr, format);
out_count = vsnprintf (buffer, size, format, argptr);
va_end (argptr);
/* OUT_COUNT now is number of bytes needed, not counting final null. */
if (out_count + 1 <= size)
break;
/* If it did not fit, try again with more space. */
free (buffer);
size = out_count + 1;
}
/* Now we have the desired output in BUFFER. Output it. */
subst_fwrite (buffer, 1, out_count, stdout);
return out_count;
}
int
subst_fprintf (FILE *stream, const char *format, ...)
{
int out_count;
char *buffer;
int size = 1000;
while (1)
{
va_list argptr;
buffer = (char *) malloc (size);
/* Format it into BUFFER, as much as fits. */
va_start (argptr, format);
out_count = vsnprintf (buffer, size, format, argptr);
va_end (argptr);
/* OUT_COUNT now is number of bytes needed, not counting final null. */
if (out_count + 1 <= size)
break;
/* If it did not fit, try again with more space. */
free (buffer);
size = out_count + 1;
}
/* Now we have the desired output in BUFFER. Output it. */
subst_fwrite (buffer, 1, out_count, stream);
return out_count;
}
int
subst_vprintf (const char *format, va_list ap)
{
int out_count;
char *buffer;
int size = 1000;
while (1)
{
va_list argptr;
buffer = (char *) malloc (size);
/* Format it into BUFFER, as much as fits. */
va_copy (argptr, ap);
out_count = vsnprintf (buffer, size, format, argptr);
va_end (argptr);
/* OUT_COUNT now is number of bytes needed, not counting final null. */
if (out_count + 1 <= size)
break;
/* If it did not fit, try again with more space. */
free (buffer);
size = out_count + 1;
}
/* Now we have the desired output in BUFFER. Output it. */
subst_fwrite (buffer, 1, out_count, stdout);
return out_count;
}
int
subst_vfprintf (FILE *stream, const char *format, va_list ap)
{
int out_count;
char *buffer;
int size = 1000;
while (1)
{
va_list argptr;
buffer = (char *) malloc (size);
/* Format it into BUFFER, as much as fits. */
va_copy (argptr, ap);
out_count = vsnprintf (buffer, size, format, argptr);
va_end (argptr);
/* OUT_COUNT now is number of bytes needed, not counting final null. */
if (out_count + 1 <= size)
break;
/* If it did not fit, try again with more space. */
free (buffer);
size = out_count + 1;
}
/* Now we have the desired output in BUFFER. Output it. */
subst_fwrite (buffer, 1, out_count, stream);
return out_count;
}
int
subst_putchar (char c)
{
return (subst_fwrite (&c, 1, 1, stdout) < 1 ? EOF
: (int) (unsigned char) c);
}
/* This serves for fputs also. */
int
subst_putc (char c, FILE *stream)
{
return (subst_fwrite (&c, 1, 1, stream) < 1 ? EOF
: (int) (unsigned char) c);
}
int
subst_puts (char *s)
{
size_t len = strlen (s);
return (subst_fwrite (s, 1, len, stdout) < len ? EOF : 0);
}
int
subst_fputs (char *s, FILE *stream)
{
size_t len = strlen (s);
return (subst_fwrite (s, 1, len, stream) < len ? EOF : 0);
}
int
subst_fwrite (char *buffer, size_t size, size_t count, FILE *stream)
{
int count_left = count;
int desc = fileno (stream);
while (1)
{
int written;
fd_set set;
written = fwrite (buffer, size, count_left, stream);
if (written == count_left)
break;
/* Wait for space to be available. */
FD_ZERO (&set);
FD_SET (desc, &set);
select (desc + 1, NULL, &set, NULL, NULL);
buffer += written;
count_left -= written;
}
return count;
}
- Re: CVS problem with ssh, Derek Price, 2005/07/13
- Re: CVS problem with ssh, Paul Eggert, 2005/07/13
- Re: CVS problem with ssh, Richard M. Stallman, 2005/07/14
- Re: CVS problem with ssh, Paul Eggert, 2005/07/14
- Re: CVS problem with ssh, Richard M. Stallman, 2005/07/15
- Re: CVS problem with ssh, Larry Jones, 2005/07/15
- Re: CVS problem with ssh, Richard M. Stallman, 2005/07/15
- Re: CVS problem with ssh, Larry Jones, 2005/07/15
- Re: CVS problem with ssh, Richard M. Stallman, 2005/07/16