mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-11-30 13:01:23 +03:00
Reformat most of the function headers
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
committed by
Andreas Schneider
parent
daabd78742
commit
2aa137947a
217
src/misc.c
217
src/misc.c
@@ -104,7 +104,8 @@
|
||||
*/
|
||||
|
||||
#ifdef _WIN32
|
||||
char *ssh_get_user_home_dir(void) {
|
||||
char *ssh_get_user_home_dir(void)
|
||||
{
|
||||
char tmp[PATH_MAX] = {0};
|
||||
char *szPath = NULL;
|
||||
|
||||
@@ -122,12 +123,13 @@ char *ssh_get_user_home_dir(void) {
|
||||
}
|
||||
|
||||
/* we have read access on file */
|
||||
int ssh_file_readaccess_ok(const char *file) {
|
||||
if (_access(file, 4) < 0) {
|
||||
return 0;
|
||||
}
|
||||
int ssh_file_readaccess_ok(const char *file)
|
||||
{
|
||||
if (_access(file, 4) < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -158,7 +160,8 @@ int ssh_dir_writeable(const char *path)
|
||||
#define SSH_USEC_IN_SEC 1000000LL
|
||||
#define SSH_SECONDS_SINCE_1601 11644473600LL
|
||||
|
||||
int gettimeofday(struct timeval *__p, void *__t) {
|
||||
int gettimeofday(struct timeval *__p, void *__t)
|
||||
{
|
||||
union {
|
||||
unsigned long long ns100; /* time since 1 Jan 1601 in 100ns units */
|
||||
FILETIME ft;
|
||||
@@ -171,7 +174,8 @@ int gettimeofday(struct timeval *__p, void *__t) {
|
||||
return (0);
|
||||
}
|
||||
|
||||
char *ssh_get_local_username(void) {
|
||||
char *ssh_get_local_username(void)
|
||||
{
|
||||
DWORD size = 0;
|
||||
char *user;
|
||||
|
||||
@@ -190,7 +194,8 @@ char *ssh_get_local_username(void) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int ssh_is_ipaddr_v4(const char *str) {
|
||||
int ssh_is_ipaddr_v4(const char *str)
|
||||
{
|
||||
struct sockaddr_storage ss;
|
||||
int sslen = sizeof(ss);
|
||||
int rc = SOCKET_ERROR;
|
||||
@@ -212,7 +217,8 @@ int ssh_is_ipaddr_v4(const char *str) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ssh_is_ipaddr(const char *str) {
|
||||
int ssh_is_ipaddr(const char *str)
|
||||
{
|
||||
int rc = SOCKET_ERROR;
|
||||
|
||||
if (strchr(str, ':')) {
|
||||
@@ -319,7 +325,8 @@ char *ssh_get_local_username(void)
|
||||
return name;
|
||||
}
|
||||
|
||||
int ssh_is_ipaddr_v4(const char *str) {
|
||||
int ssh_is_ipaddr_v4(const char *str)
|
||||
{
|
||||
int rc = -1;
|
||||
struct in_addr dest;
|
||||
|
||||
@@ -331,7 +338,8 @@ int ssh_is_ipaddr_v4(const char *str) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ssh_is_ipaddr(const char *str) {
|
||||
int ssh_is_ipaddr(const char *str)
|
||||
{
|
||||
int rc = -1;
|
||||
|
||||
if (strchr(str, ':')) {
|
||||
@@ -349,7 +357,8 @@ int ssh_is_ipaddr(const char *str) {
|
||||
|
||||
#endif /* _WIN32 */
|
||||
|
||||
char *ssh_lowercase(const char* str) {
|
||||
char *ssh_lowercase(const char* str)
|
||||
{
|
||||
char *new, *p;
|
||||
|
||||
if (str == NULL) {
|
||||
@@ -392,15 +401,17 @@ char *ssh_hostport(const char *host, int port)
|
||||
* @brief Convert a buffer into a colon separated hex string.
|
||||
* The caller has to free the memory.
|
||||
*
|
||||
* @param what What should be converted to a hex string.
|
||||
* @param[in] what What should be converted to a hex string.
|
||||
*
|
||||
* @param len Length of the buffer to convert.
|
||||
* @param[in] len Length of the buffer to convert.
|
||||
*
|
||||
* @return The hex string or NULL on error.
|
||||
* @return The hex string or NULL on error. The memory needs
|
||||
* to be freed using ssh_string_free_char().
|
||||
*
|
||||
* @see ssh_string_free_char()
|
||||
*/
|
||||
char *ssh_get_hexa(const unsigned char *what, size_t len) {
|
||||
char *ssh_get_hexa(const unsigned char *what, size_t len)
|
||||
{
|
||||
const char h[] = "0123456789abcdef";
|
||||
char *hexa;
|
||||
size_t i;
|
||||
@@ -428,7 +439,8 @@ char *ssh_get_hexa(const unsigned char *what, size_t len) {
|
||||
/**
|
||||
* @deprecated Please use ssh_print_hash() instead
|
||||
*/
|
||||
void ssh_print_hexa(const char *descr, const unsigned char *what, size_t len) {
|
||||
void ssh_print_hexa(const char *descr, const unsigned char *what, size_t len)
|
||||
{
|
||||
char *hexa = ssh_get_hexa(what, len);
|
||||
|
||||
if (hexa == NULL) {
|
||||
@@ -649,48 +661,54 @@ error:
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
const char *ssh_version(int req_version) {
|
||||
if (req_version <= LIBSSH_VERSION_INT) {
|
||||
return SSH_STRINGIFY(LIBSSH_VERSION) GCRYPT_STRING CRYPTO_STRING MBED_STRING
|
||||
ZLIB_STRING;
|
||||
}
|
||||
const char *ssh_version(int req_version)
|
||||
{
|
||||
if (req_version <= LIBSSH_VERSION_INT) {
|
||||
return SSH_STRINGIFY(LIBSSH_VERSION) GCRYPT_STRING CRYPTO_STRING
|
||||
MBED_STRING ZLIB_STRING;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct ssh_list *ssh_list_new(void) {
|
||||
struct ssh_list *ret=malloc(sizeof(struct ssh_list));
|
||||
if(!ret)
|
||||
return NULL;
|
||||
ret->root=ret->end=NULL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ssh_list_free(struct ssh_list *list){
|
||||
struct ssh_iterator *ptr,*next;
|
||||
if(!list)
|
||||
return;
|
||||
ptr=list->root;
|
||||
while(ptr){
|
||||
next=ptr->next;
|
||||
SAFE_FREE(ptr);
|
||||
ptr=next;
|
||||
}
|
||||
SAFE_FREE(list);
|
||||
struct ssh_list *ssh_list_new(void)
|
||||
{
|
||||
struct ssh_list *ret = malloc(sizeof(struct ssh_list));
|
||||
if (!ret)
|
||||
return NULL;
|
||||
ret->root = ret->end = NULL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
struct ssh_iterator *ssh_list_get_iterator(const struct ssh_list *list){
|
||||
if(!list)
|
||||
void ssh_list_free(struct ssh_list *list)
|
||||
{
|
||||
struct ssh_iterator *ptr, *next;
|
||||
if (!list)
|
||||
return;
|
||||
ptr = list->root;
|
||||
while (ptr) {
|
||||
next = ptr->next;
|
||||
SAFE_FREE(ptr);
|
||||
ptr = next;
|
||||
}
|
||||
SAFE_FREE(list);
|
||||
}
|
||||
|
||||
struct ssh_iterator *ssh_list_get_iterator(const struct ssh_list *list)
|
||||
{
|
||||
if (!list)
|
||||
return NULL;
|
||||
return list->root;
|
||||
}
|
||||
|
||||
struct ssh_iterator *ssh_list_find(const struct ssh_list *list, void *value)
|
||||
{
|
||||
struct ssh_iterator *it;
|
||||
|
||||
for (it = ssh_list_get_iterator(list); it != NULL ; it = it->next)
|
||||
if (it->data == value)
|
||||
return it;
|
||||
return NULL;
|
||||
return list->root;
|
||||
}
|
||||
|
||||
struct ssh_iterator *ssh_list_find(const struct ssh_list *list, void *value){
|
||||
struct ssh_iterator *it;
|
||||
for(it = ssh_list_get_iterator(list); it != NULL ;it=it->next)
|
||||
if(it->data==value)
|
||||
return it;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -712,16 +730,19 @@ size_t ssh_list_count(const struct ssh_list *list)
|
||||
return count;
|
||||
}
|
||||
|
||||
static struct ssh_iterator *ssh_iterator_new(const void *data){
|
||||
struct ssh_iterator *iterator=malloc(sizeof(struct ssh_iterator));
|
||||
if(!iterator)
|
||||
return NULL;
|
||||
iterator->next=NULL;
|
||||
iterator->data=data;
|
||||
return iterator;
|
||||
static struct ssh_iterator *ssh_iterator_new(const void *data)
|
||||
{
|
||||
struct ssh_iterator *iterator = malloc(sizeof(struct ssh_iterator));
|
||||
|
||||
if (!iterator)
|
||||
return NULL;
|
||||
iterator->next = NULL;
|
||||
iterator->data = data;
|
||||
return iterator;
|
||||
}
|
||||
|
||||
int ssh_list_append(struct ssh_list *list,const void *data){
|
||||
int ssh_list_append(struct ssh_list *list,const void *data)
|
||||
{
|
||||
struct ssh_iterator *iterator = NULL;
|
||||
|
||||
if (list == NULL) {
|
||||
@@ -744,7 +765,8 @@ int ssh_list_append(struct ssh_list *list,const void *data){
|
||||
return SSH_OK;
|
||||
}
|
||||
|
||||
int ssh_list_prepend(struct ssh_list *list, const void *data){
|
||||
int ssh_list_prepend(struct ssh_list *list, const void *data)
|
||||
{
|
||||
struct ssh_iterator *it = NULL;
|
||||
|
||||
if (list == NULL) {
|
||||
@@ -768,8 +790,9 @@ int ssh_list_prepend(struct ssh_list *list, const void *data){
|
||||
return SSH_OK;
|
||||
}
|
||||
|
||||
void ssh_list_remove(struct ssh_list *list, struct ssh_iterator *iterator){
|
||||
struct ssh_iterator *ptr,*prev;
|
||||
void ssh_list_remove(struct ssh_list *list, struct ssh_iterator *iterator)
|
||||
{
|
||||
struct ssh_iterator *ptr, *prev;
|
||||
|
||||
if (list == NULL) {
|
||||
return;
|
||||
@@ -808,7 +831,8 @@ void ssh_list_remove(struct ssh_list *list, struct ssh_iterator *iterator){
|
||||
* @returns A pointer to the element being stored in head, or NULL
|
||||
* if the list is empty.
|
||||
*/
|
||||
const void *_ssh_list_pop_head(struct ssh_list *list){
|
||||
const void *_ssh_list_pop_head(struct ssh_list *list)
|
||||
{
|
||||
struct ssh_iterator *iterator = NULL;
|
||||
const void *data = NULL;
|
||||
|
||||
@@ -847,7 +871,8 @@ const void *_ssh_list_pop_head(struct ssh_list *list){
|
||||
*
|
||||
* @see ssh_string_free_char()
|
||||
*/
|
||||
char *ssh_dirname (const char *path) {
|
||||
char *ssh_dirname (const char *path)
|
||||
{
|
||||
char *new = NULL;
|
||||
size_t len;
|
||||
|
||||
@@ -905,7 +930,8 @@ char *ssh_dirname (const char *path) {
|
||||
*
|
||||
* @see ssh_string_free_char()
|
||||
*/
|
||||
char *ssh_basename (const char *path) {
|
||||
char *ssh_basename (const char *path)
|
||||
{
|
||||
char *new = NULL;
|
||||
const char *s;
|
||||
size_t len;
|
||||
@@ -1043,7 +1069,8 @@ int ssh_mkdirs(const char *pathname, mode_t mode)
|
||||
*
|
||||
* @see ssh_string_free_char()
|
||||
*/
|
||||
char *ssh_path_expand_tilde(const char *d) {
|
||||
char *ssh_path_expand_tilde(const char *d)
|
||||
{
|
||||
char *h = NULL, *r;
|
||||
const char *p;
|
||||
size_t ld;
|
||||
@@ -1115,7 +1142,8 @@ char *ssh_path_expand_tilde(const char *d) {
|
||||
*
|
||||
* @see ssh_string_free_char()
|
||||
*/
|
||||
char *ssh_path_expand_escape(ssh_session session, const char *s) {
|
||||
char *ssh_path_expand_escape(ssh_session session, const char *s)
|
||||
{
|
||||
char host[NI_MAXHOST] = {0};
|
||||
char *buf = NULL;
|
||||
char *r = NULL;
|
||||
@@ -1376,7 +1404,8 @@ done:
|
||||
* @brief initializes a timestamp to the current time
|
||||
* @param[out] ts pointer to an allocated ssh_timestamp structure
|
||||
*/
|
||||
void ssh_timestamp_init(struct ssh_timestamp *ts){
|
||||
void ssh_timestamp_init(struct ssh_timestamp *ts)
|
||||
{
|
||||
#ifdef HAVE_CLOCK_GETTIME
|
||||
struct timespec tp;
|
||||
clock_gettime(CLOCK, &tp);
|
||||
@@ -1399,17 +1428,18 @@ void ssh_timestamp_init(struct ssh_timestamp *ts){
|
||||
* @returns difference in milliseconds
|
||||
*/
|
||||
|
||||
static int ssh_timestamp_difference(struct ssh_timestamp *old,
|
||||
struct ssh_timestamp *new){
|
||||
long seconds, usecs, msecs;
|
||||
seconds = new->seconds - old->seconds;
|
||||
usecs = new->useconds - old->useconds;
|
||||
if (usecs < 0){
|
||||
seconds--;
|
||||
usecs += 1000000;
|
||||
}
|
||||
msecs = seconds * 1000 + usecs/1000;
|
||||
return msecs;
|
||||
static int
|
||||
ssh_timestamp_difference(struct ssh_timestamp *old, struct ssh_timestamp *new)
|
||||
{
|
||||
long seconds, usecs, msecs;
|
||||
seconds = new->seconds - old->seconds;
|
||||
usecs = new->useconds - old->useconds;
|
||||
if (usecs < 0){
|
||||
seconds--;
|
||||
usecs += 1000000;
|
||||
}
|
||||
msecs = seconds * 1000 + usecs/1000;
|
||||
return msecs;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1420,14 +1450,15 @@ static int ssh_timestamp_difference(struct ssh_timestamp *old,
|
||||
* @param[in] usec number of microseconds
|
||||
* @returns milliseconds, or 10000 if user supplied values are equal to zero
|
||||
*/
|
||||
int ssh_make_milliseconds(long sec, long usec) {
|
||||
int res = usec ? (usec / 1000) : 0;
|
||||
res += (sec * 1000);
|
||||
if (res == 0) {
|
||||
res = 10 * 1000; /* use a reasonable default value in case
|
||||
* SSH_OPTIONS_TIMEOUT is not set in options. */
|
||||
}
|
||||
return res;
|
||||
int ssh_make_milliseconds(long sec, long usec)
|
||||
{
|
||||
int res = usec ? (usec / 1000) : 0;
|
||||
res += (sec * 1000);
|
||||
if (res == 0) {
|
||||
res = 10 * 1000; /* use a reasonable default value in case
|
||||
* SSH_OPTIONS_TIMEOUT is not set in options. */
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1440,7 +1471,8 @@ int ssh_make_milliseconds(long sec, long usec) {
|
||||
* @returns 1 if timeout is elapsed
|
||||
* 0 otherwise
|
||||
*/
|
||||
int ssh_timeout_elapsed(struct ssh_timestamp *ts, int timeout) {
|
||||
int ssh_timeout_elapsed(struct ssh_timestamp *ts, int timeout)
|
||||
{
|
||||
struct ssh_timestamp now;
|
||||
|
||||
switch(timeout) {
|
||||
@@ -1472,7 +1504,8 @@ int ssh_timeout_elapsed(struct ssh_timestamp *ts, int timeout) {
|
||||
* timeout
|
||||
* @returns remaining time in milliseconds, 0 if elapsed, -1 if never.
|
||||
*/
|
||||
int ssh_timeout_update(struct ssh_timestamp *ts, int timeout){
|
||||
int ssh_timeout_update(struct ssh_timestamp *ts, int timeout)
|
||||
{
|
||||
struct ssh_timestamp now;
|
||||
int ms, ret;
|
||||
if (timeout <= 0) {
|
||||
@@ -1795,7 +1828,7 @@ int ssh_newline_vis(const char *string, char *buf, size_t buf_len)
|
||||
*
|
||||
* @brief Replaces the last 6 characters of a string from 'X' to 6 random hexdigits.
|
||||
*
|
||||
* @param[in] template Any input string with last 6 characters as 'X'.
|
||||
* @param[in,out] template Any input string with last 6 characters as 'X'.
|
||||
* @returns -1 as error when the last 6 characters of the input to be replaced are not 'X'
|
||||
* 0 otherwise.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user