mirror of
https://github.com/libssh2/libssh2.git
synced 2026-10-24 03:48:58 +03:00
example: drop two local macros, merge/simplify header guards
Also: include standard headers first to not interfere with Windows redefinitions. Closes #2498
This commit is contained in:
@@ -6,13 +6,15 @@
|
||||
#include "libssh2_setup.h"
|
||||
#include <libssh2.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <ws2tcpip.h> /* for socklen_t */
|
||||
#define recv(s, b, l, f) recv(s, b, (int)(l), f)
|
||||
#define send(s, b, l, f) send(s, b, (int)(l), f)
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32
|
||||
#else
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
@@ -29,10 +31,6 @@
|
||||
#include <sys/time.h> /* for timeval */
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifndef INADDR_NONE
|
||||
#define INADDR_NONE ((in_addr_t)~0)
|
||||
#endif
|
||||
|
||||
@@ -8,11 +8,11 @@
|
||||
#include "libssh2_setup.h"
|
||||
#include <libssh2.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#define write(f, b, c) _write(f, b, (unsigned int)(c))
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32
|
||||
#else
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
@@ -23,8 +23,6 @@
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
static const char *pubkey = "/home/username/.ssh/id_rsa.pub";
|
||||
static const char *privkey = "/home/username/.ssh/id_rsa";
|
||||
static const char *username = "username";
|
||||
|
||||
@@ -13,11 +13,11 @@
|
||||
#include "libssh2_setup.h"
|
||||
#include <libssh2.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#define write(f, b, c) _write(f, b, (unsigned int)(c))
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32
|
||||
#else
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
@@ -34,8 +34,6 @@
|
||||
#include <sys/time.h> /* for timeval, gettimeofday() */
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
static const char *pubkey = "/home/username/.ssh/id_rsa.pub";
|
||||
static const char *privkey = "/home/username/.ssh/id_rsa";
|
||||
static const char *username = "username";
|
||||
@@ -47,15 +45,13 @@ static int gettimeofday(struct timeval *tp, void *tzp)
|
||||
{
|
||||
(void)tzp;
|
||||
if(tp) {
|
||||
/* Offset between 1601-01-01 and 1970-01-01 in 100 nanosec units */
|
||||
#define WIN32_FT_OFFSET 116444736000000000
|
||||
union {
|
||||
libssh2_uint64_t ns100; /* time since 1 Jan 1601 in 100ns units */
|
||||
FILETIME ft;
|
||||
} now;
|
||||
GetSystemTimeAsFileTime(&now.ft);
|
||||
tp->tv_usec = (long)((now.ns100 / 10) % 1000000);
|
||||
tp->tv_sec = (long)((now.ns100 - WIN32_FT_OFFSET) / 10000000);
|
||||
tp->tv_sec = (long)((now.ns100 - 116444736000000000) / 10000000);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -8,17 +8,6 @@
|
||||
#include "libssh2_setup.h"
|
||||
#include <libssh2.h>
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETINET_IN_H
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
#ifdef HAVE_ARPA_INET_H
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
@@ -27,6 +16,15 @@
|
||||
#undef fstat
|
||||
#define fstat _fstat
|
||||
#define fileno _fileno
|
||||
#else
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETINET_IN_H
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
#ifdef HAVE_ARPA_INET_H
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
static const char *pubkey = "/home/username/.ssh/id_rsa.pub";
|
||||
|
||||
@@ -8,7 +8,16 @@
|
||||
#include "libssh2_setup.h"
|
||||
#include <libssh2.h>
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <stdio.h>
|
||||
#include <time.h> /* for time() */
|
||||
|
||||
#ifdef _WIN32
|
||||
#undef stat
|
||||
#define stat _stat
|
||||
#undef fstat
|
||||
#define fstat _fstat
|
||||
#define fileno _fileno
|
||||
#else
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
@@ -25,17 +34,6 @@
|
||||
#include <sys/time.h> /* for timeval */
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <time.h> /* for time() */
|
||||
|
||||
#ifdef _WIN32
|
||||
#undef stat
|
||||
#define stat _stat
|
||||
#undef fstat
|
||||
#define fstat _fstat
|
||||
#define fileno _fileno
|
||||
#endif
|
||||
|
||||
static const char *pubkey = "/home/username/.ssh/id_rsa.pub";
|
||||
static const char *privkey = "/home/username/.ssh/id_rsa";
|
||||
static const char *username = "username";
|
||||
|
||||
@@ -14,12 +14,13 @@
|
||||
#include <libssh2.h>
|
||||
#include <libssh2_sftp.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#define strdup _strdup
|
||||
#define write(f, b, c) _write(f, b, (unsigned int)(c))
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32
|
||||
#else
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
@@ -30,9 +31,6 @@
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static const char *pubkey = "/home/username/.ssh/id_rsa.pub";
|
||||
static const char *privkey = "/home/username/.ssh/id_rsa";
|
||||
static const char *username = "username";
|
||||
|
||||
@@ -14,11 +14,11 @@
|
||||
#include <libssh2.h>
|
||||
#include <libssh2_sftp.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#define write(f, b, c) _write(f, b, (unsigned int)(c))
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32
|
||||
#else
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
@@ -32,8 +32,6 @@
|
||||
#include <sys/time.h> /* for timeval */
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
static const char *pubkey = "/home/username/.ssh/id_rsa.pub";
|
||||
static const char *privkey = "/home/username/.ssh/id_rsa";
|
||||
static const char *username = "username";
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
#include <libssh2.h>
|
||||
#include <libssh2_sftp.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
@@ -25,8 +27,6 @@
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
static const char *pubkey = "/home/username/.ssh/id_rsa.pub";
|
||||
static const char *privkey = "/home/username/.ssh/id_rsa";
|
||||
static const char *username = "username";
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
#include <libssh2.h>
|
||||
#include <libssh2_sftp.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
@@ -25,8 +27,6 @@
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
static const char *pubkey = "/home/username/.ssh/id_rsa.pub";
|
||||
static const char *privkey = "/home/username/.ssh/id_rsa";
|
||||
static const char *username = "username";
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
#include <libssh2.h>
|
||||
#include <libssh2_sftp.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
@@ -25,8 +27,6 @@
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
static const char *pubkey = "/home/username/.ssh/id_rsa.pub";
|
||||
static const char *privkey = "/home/username/.ssh/id_rsa";
|
||||
static const char *username = "username";
|
||||
|
||||
@@ -14,11 +14,11 @@
|
||||
#include <libssh2.h>
|
||||
#include <libssh2_sftp.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#define write(f, b, c) _write(f, b, (unsigned int)(c))
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32
|
||||
#else
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
@@ -35,8 +35,6 @@
|
||||
#include <sys/time.h> /* for timeval, gettimeofday() */
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
static const char *pubkey = "/home/username/.ssh/id_rsa.pub";
|
||||
static const char *privkey = "/home/username/.ssh/id_rsa";
|
||||
static const char *username = "username";
|
||||
@@ -48,15 +46,13 @@ static int gettimeofday(struct timeval *tp, void *tzp)
|
||||
{
|
||||
(void)tzp;
|
||||
if(tp) {
|
||||
/* Offset between 1601-01-01 and 1970-01-01 in 100 nanosec units */
|
||||
#define WIN32_FT_OFFSET 116444736000000000
|
||||
union {
|
||||
libssh2_uint64_t ns100; /* time since 1 Jan 1601 in 100ns units */
|
||||
FILETIME ft;
|
||||
} now;
|
||||
GetSystemTimeAsFileTime(&now.ft);
|
||||
tp->tv_usec = (long)((now.ns100 / 10) % 1000000);
|
||||
tp->tv_sec = (long)((now.ns100 - WIN32_FT_OFFSET) / 10000000);
|
||||
tp->tv_sec = (long)((now.ns100 - 116444736000000000) / 10000000);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
#include <libssh2.h>
|
||||
#include <libssh2_sftp.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
@@ -25,8 +27,6 @@
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
static const char *pubkey = "/home/username/.ssh/id_rsa.pub";
|
||||
static const char *privkey = "/home/username/.ssh/id_rsa";
|
||||
static const char *username = "username";
|
||||
|
||||
@@ -14,6 +14,9 @@
|
||||
#include <libssh2.h>
|
||||
#include <libssh2_sftp.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <time.h> /* for time() */
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
@@ -31,9 +34,6 @@
|
||||
#include <sys/time.h> /* for timeval */
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <time.h> /* for time() */
|
||||
|
||||
static const char *pubkey = "/home/username/.ssh/id_rsa.pub";
|
||||
static const char *privkey = "/home/username/.ssh/id_rsa";
|
||||
static const char *username = "username";
|
||||
|
||||
@@ -14,6 +14,10 @@
|
||||
#include <libssh2.h>
|
||||
#include <libssh2_sftp.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <time.h> /* for time() */
|
||||
#include <string.h>
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
@@ -31,10 +35,6 @@
|
||||
#include <sys/time.h> /* for timeval */
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <time.h> /* for time() */
|
||||
#include <string.h>
|
||||
|
||||
static const char *pubkey = "/home/username/.ssh/id_rsa.pub";
|
||||
static const char *privkey = "/home/username/.ssh/id_rsa";
|
||||
static const char *username = "username";
|
||||
|
||||
@@ -14,11 +14,12 @@
|
||||
#include <libssh2.h>
|
||||
#include <libssh2_sftp.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#define strdup _strdup
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32
|
||||
#else
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
@@ -29,9 +30,6 @@
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define LIBSSH2_FILESIZE_MASK "I64u"
|
||||
#else
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
#include <libssh2.h>
|
||||
#include <libssh2_sftp.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
@@ -25,8 +27,6 @@
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define LIBSSH2_FILESIZE_MASK "I64u"
|
||||
#else
|
||||
|
||||
@@ -18,11 +18,13 @@
|
||||
#include "libssh2_setup.h"
|
||||
#include <libssh2.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#define strdup _strdup
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32
|
||||
#else
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
@@ -33,10 +35,6 @@
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static const char *pubkey = ".ssh/id_rsa.pub";
|
||||
static const char *privkey = ".ssh/id_rsa";
|
||||
static const char *username = "username";
|
||||
|
||||
@@ -12,6 +12,9 @@
|
||||
#include "libssh2_setup.h"
|
||||
#include <libssh2.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
@@ -23,9 +26,6 @@
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static const char *username = "username";
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
|
||||
@@ -16,6 +16,9 @@
|
||||
#include "libssh2_setup.h"
|
||||
#include <libssh2.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
@@ -33,9 +36,6 @@
|
||||
#include <sys/time.h> /* for timeval */
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static const char *hostname = "127.0.0.1";
|
||||
static const char *commandline = "uptime";
|
||||
static const char *username;
|
||||
|
||||
@@ -17,6 +17,9 @@
|
||||
|
||||
#ifndef LIBSSH2_NO_DEPRECATED
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
@@ -34,9 +37,6 @@
|
||||
#include <sys/time.h> /* for timeval */
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static const char *hostname = "127.0.0.1";
|
||||
static const char *commandline = "cat";
|
||||
static const char *username = "user";
|
||||
|
||||
@@ -13,6 +13,10 @@
|
||||
#include "libssh2_setup.h"
|
||||
#include <libssh2.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
@@ -30,10 +34,6 @@
|
||||
#include <sys/time.h> /* for timeval */
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static const char *hostname = "127.0.0.1";
|
||||
static const char *commandline = "uptime";
|
||||
static const char *pubkey = "/home/username/.ssh/id_rsa.pub";
|
||||
|
||||
@@ -6,6 +6,9 @@
|
||||
#include "libssh2_setup.h"
|
||||
#include <libssh2.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
@@ -17,9 +20,6 @@
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifndef INADDR_NONE
|
||||
#define INADDR_NONE ((in_addr_t)~0)
|
||||
#endif
|
||||
|
||||
@@ -6,13 +6,15 @@
|
||||
#include "libssh2_setup.h"
|
||||
#include <libssh2.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <ws2tcpip.h> /* for socklen_t */
|
||||
#define recv(s, b, l, f) recv(s, b, (int)(l), f)
|
||||
#define send(s, b, l, f) send(s, b, (int)(l), f)
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32
|
||||
#else
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
@@ -29,10 +31,6 @@
|
||||
#include <sys/time.h> /* for timeval */
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifndef INADDR_NONE
|
||||
#define INADDR_NONE ((in_addr_t)~0)
|
||||
#endif
|
||||
|
||||
@@ -16,16 +16,19 @@
|
||||
|
||||
#if defined(HAVE_SYS_UN_H) && !defined(LIBSSH2_NO_DEPRECATED)
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_IOCTL_H
|
||||
#include <sys/ioctl.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETINET_IN_H
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
#ifndef _WIN32
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_SELECT_H
|
||||
#include <sys/select.h>
|
||||
#endif
|
||||
@@ -39,9 +42,6 @@
|
||||
#include <sys/un.h>
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <termios.h>
|
||||
|
||||
#define PATH_UNIX_X "/tmp/.X11-unix/X%d"
|
||||
|
||||
Reference in New Issue
Block a user