ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

fake.c
Go to the documentation of this file.
00001 #include "precomp.h"
00002 
00003 #define MAX_ASCII 100
00004 
00005 int checkRecv(SOCKET s);
00006 
00007 int checkRecv(SOCKET s)
00008 {
00009    int testVal;
00010    fd_set sSet;
00011    struct timeval timeout;
00012    timeout.tv_sec = 60;
00013 
00014    FD_ZERO(&sSet);
00015 
00016    FD_SET(s, &sSet);
00017 
00018    testVal = select(0, &sSet, NULL, NULL, &timeout);
00019 
00020    if (testVal == SOCKET_ERROR)
00021       fprintf(stderr, "Socket Error");
00022 
00023    return testVal;
00024 }
00025 
00026 void blkfree(char **av0)
00027 {
00028     register char **av = av0;
00029 
00030     while (*av)
00031         free(*av++);
00032 }
00033 
00034 char **glob(const char *v)
00035 {
00036    return NULL;
00037 }
00038 
00039 int sleep(int time)
00040 {
00041    return time;
00042 }
00043 
00044 int herror(char *string)
00045 {
00046    return 0;
00047 }
00048 
00049 #if 0
00050 int gettimeofday(struct timeval *timenow,
00051                  struct timezone *zone)
00052 {
00053     time_t t;
00054 
00055     t = clock();
00056 
00057     timenow->tv_usec = t;
00058     timenow->tv_sec = t / CLK_TCK;
00059 
00060     return 0;
00061 }
00062 
00063 int fgetcSocket(int s)
00064 {
00065    int c;
00066    char buffer[10];
00067 
00068 //   checkRecv(s);
00069 
00070    c = recv(s, buffer, 1, 0);
00071 
00072 #ifdef DEBUG_IN
00073    printf("%c", buffer[0]);
00074 #endif
00075 
00076    if (c == INVALID_SOCKET)
00077       return c;
00078 
00079    if (c == 0)
00080       return EOF;
00081 
00082    return buffer[0];
00083 }
00084 
00085 #else
00086 
00087 int fgetcSocket(int s)
00088 {
00089    static int index = 0;
00090    static int total = 0;
00091    static char buffer[4096];
00092 
00093    if (index == total)
00094      {
00095        index = 0;
00096        total = recv(s, buffer, sizeof(buffer), 0);
00097 
00098        if (total == SOCKET_ERROR)
00099      {
00100        total = 0;
00101        return ERROR;
00102      }
00103 
00104        if (total == 0)
00105      return EOF;
00106      }
00107    return buffer[index++];
00108 }
00109 
00110 #endif
00111 
00112 const char *fprintfSocket(int s, const char *format, ...)
00113 {
00114    va_list argptr;
00115    char buffer[10009];
00116 
00117    va_start(argptr, format);
00118    vsprintf(buffer, format, argptr);
00119    va_end(argptr);
00120 
00121    send(s, buffer, strlen(buffer), 0);
00122 
00123    return NULL;
00124 }
00125 
00126 const char *fputsSocket(const char *format, int s)
00127 {
00128    send(s, format, strlen(format), 0);
00129 
00130    return NULL;
00131 }
00132 
00133 int fputcSocket(int s, char putChar)
00134 {
00135    char buffer[2];
00136 
00137    buffer[0] = putChar;
00138    buffer[1] = '\0';
00139 
00140    if(SOCKET_ERROR==send(s, buffer, 1, 0)) {
00141        int iret=WSAGetLastError ();
00142        fprintf(stdout,"fputcSocket: %d\n",iret);
00143        return 0;
00144    }
00145    else {
00146     return putChar;
00147    }
00148 }
00149 int fputSocket(int s, char *buffer, int len)
00150 {
00151     int iret;
00152     while(len) {
00153         if(SOCKET_ERROR==(iret=send(s, buffer, len, 0)))
00154         {
00155             iret=WSAGetLastError ();
00156             fprintf(stdout,"fputcSocket: %d\n",iret);
00157             return 0;
00158         }
00159         else {
00160             return len-=iret;
00161         }
00162     }
00163     return 0;
00164 }
00165 
00166 char *fgetsSocket(int s, char *string)
00167 {
00168    char buffer[2] = {0};
00169    int i, count;
00170 
00171    for (i = 0, count = 1; count != 0 && buffer[0] != '\n'; i++)
00172    {
00173       checkRecv(s);
00174 
00175       count = recv(s, buffer, 1, 0);
00176 
00177       if (count == SOCKET_ERROR)
00178       {
00179      printf("Error in fgetssocket");
00180      return NULL;
00181       }
00182 
00183       if (count == 1)
00184       {
00185      string[i] = buffer[0];
00186 
00187      if (i == MAX_ASCII - 3)
00188      {
00189         count = 0;
00190         string[++i] = '\n';
00191         string[++i] = '\0';
00192      }
00193       }
00194       else
00195       {
00196      if (i == 0)
00197         return NULL;
00198      else
00199      {
00200         string[i] = '\n';
00201         string[i + 1] = '\0'; // This is risky
00202         return string;
00203      }
00204 
00205       }
00206 
00207    }
00208    string[i] = '\0';
00209 
00210 #ifdef DEBUG_IN
00211    printf("%s", string);
00212 #endif
00213    return string;
00214 }
00215 
00216 
00217 #if 0
00218 char *getpass(const char *prompt)
00219 {
00220    static char string[64];
00221 
00222    printf("%s", prompt);
00223 
00224    gets(string);
00225 
00226    return string;
00227 }
00228 #endif
00229 char *getpass (const char * prompt)
00230 {
00231   static char input[256];
00232   HANDLE in;
00233   HANDLE err;
00234   DWORD    count;
00235 
00236   in = GetStdHandle (STD_INPUT_HANDLE);
00237   err = GetStdHandle (STD_ERROR_HANDLE);
00238 
00239   if (in == INVALID_HANDLE_VALUE || err == INVALID_HANDLE_VALUE)
00240     return NULL;
00241 
00242   if (WriteFile (err, prompt, strlen (prompt), &count, NULL))
00243     {
00244       int istty = (GetFileType (in) == FILE_TYPE_CHAR);
00245       DWORD old_flags;
00246       int rc;
00247 
00248       if (istty)
00249     {
00250       if (GetConsoleMode (in, &old_flags))
00251         SetConsoleMode (in, ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT);
00252       else
00253         istty = 0;
00254     }
00255       /* Need to read line one byte at time to avoid blocking, if not a
00256          tty, so always do it this way.  */
00257       count = 0;
00258       while (1)
00259     {
00260       DWORD  dummy;
00261       char   one_char;
00262 
00263       rc = ReadFile (in, &one_char, 1, &dummy, NULL);
00264       if (rc == 0)
00265         break;
00266       if (one_char == '\r')
00267         {
00268           /* CR is always followed by LF if reading from tty.  */
00269           if (istty)
00270         continue;
00271           else
00272         break;
00273         }
00274       if (one_char == '\n')
00275         break;
00276       /* Silently truncate password string if overly long.  */
00277       if (count < sizeof (input) - 1)
00278         input[count++] = one_char;
00279     }
00280       input[count] = '\0';
00281 
00282       WriteFile (err, "\r\n", 2, &count, NULL);
00283       if (istty)
00284     SetConsoleMode (in, old_flags);
00285       if (rc)
00286     return input;
00287     }
00288 
00289   return NULL;
00290 }
00291 
00292 #if 0
00293 // Stubbed out here. Should be changed in Source code...
00294 int access(const char *filename, int accessmethod)
00295 {
00296    return 0;
00297 }
00298 #endif
00299 
00300 #ifndef __GNUC__
00301 #define EPOCHFILETIME (116444736000000000i64)
00302 #else
00303 #define EPOCHFILETIME (116444736000000000LL)
00304 #endif
00305 
00306 int gettimeofday(struct timeval *tv, struct timezone *tz)
00307 {
00308     FILETIME        ft;
00309     LARGE_INTEGER   li;
00310     __int64         t;
00311     static int      tzflag;
00312 
00313     if (tv)
00314     {
00315         GetSystemTimeAsFileTime(&ft);
00316         li.LowPart  = ft.dwLowDateTime;
00317         li.HighPart = ft.dwHighDateTime;
00318         t  = li.QuadPart;       /* In 100-nanosecond intervals */
00319         t -= EPOCHFILETIME;     /* Offset to the Epoch time */
00320         t /= 10;                /* In microseconds */
00321         tv->tv_sec  = (long)(t / 1000000);
00322         tv->tv_usec = (long)(t % 1000000);
00323     }
00324 
00325     if (tz)
00326     {
00327         if (!tzflag)
00328         {
00329             _tzset();
00330             tzflag++;
00331         }
00332         tz->tz_minuteswest = _timezone / 60;
00333         tz->tz_dsttime = _daylight;
00334     }
00335 
00336     return 0;
00337 }

Generated on Sun May 27 2012 04:17:13 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.