Skip to content

Commit

Permalink
add .clang-format from Linux kernel and format sources
Browse files Browse the repository at this point in the history
The exception is that ColumnLimit is 90.
  • Loading branch information
upa committed Feb 6, 2024
1 parent 4f0669f commit 93f155c
Show file tree
Hide file tree
Showing 14 changed files with 1,335 additions and 642 deletions.
745 changes: 745 additions & 0 deletions .clang-format

Large diffs are not rendered by default.

24 changes: 8 additions & 16 deletions src/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ static inline refcnt refcnt_dec(refcnt *cnt)
return __sync_sub_and_fetch(cnt, 1);
}


/* mutex */

typedef pthread_mutex_t lock;
Expand All @@ -45,14 +44,11 @@ static inline void lock_release_via_cleanup(void *l)
lock_release(l);
}

#define LOCK_ACQUIRE(l) \
lock_acquire(l); \
#define LOCK_ACQUIRE(l) \
lock_acquire(l); \
pthread_cleanup_push(lock_release_via_cleanup, l)

#define LOCK_RELEASE() \
pthread_cleanup_pop(1)


#define LOCK_RELEASE() pthread_cleanup_pop(1)

/* read/write lock */
typedef pthread_rwlock_t rwlock;
Expand Down Expand Up @@ -85,18 +81,14 @@ static inline void rwlock_release_via_cleanup(void *rw)
rwlock_release(rw);
}

#define RWLOCK_READ_ACQUIRE(rw) \
rwlock_read_acquire(rw); \
#define RWLOCK_READ_ACQUIRE(rw) \
rwlock_read_acquire(rw); \
pthread_cleanup_push(rwlock_release_via_cleanup, rw)

#define RWLOCK_WRITE_ACQUIRE(rw) \
rwlock_write_acquire(rw); \
#define RWLOCK_WRITE_ACQUIRE(rw) \
rwlock_write_acquire(rw); \
pthread_cleanup_push(rwlock_release_via_cleanup, rw)


#define RWLOCK_RELEASE() \
pthread_cleanup_pop(1)


#define RWLOCK_RELEASE() pthread_cleanup_pop(1)

#endif /* _ATOMIC_H_ */
40 changes: 17 additions & 23 deletions src/fileops.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include <print.h>
#include <platform.h>


sftp_session __thread tls_sftp;
/* tls_sftp is used *_wrapped() functions */

Expand All @@ -25,7 +24,7 @@ static void sftp_err_to_errno(sftp_session sftp)
{
int sftperr = sftp_get_error(sftp);

switch (sftperr){
switch (sftperr) {
case SSH_FX_OK:
case SSH_FX_EOF:
errno = 0;
Expand Down Expand Up @@ -67,7 +66,6 @@ static void sftp_err_to_errno(sftp_session sftp)
}
}


MDIR *mscp_opendir(const char *path, sftp_session sftp)
{
MDIR *md;
Expand Down Expand Up @@ -112,7 +110,6 @@ void mscp_closedir(MDIR *md)
free(md);
}


struct dirent __thread tls_dirent;
/* tls_dirent contains dirent converted from sftp_attributes returned
* from sftp_readdir(). This trick is derived from openssh's
Expand Down Expand Up @@ -161,26 +158,25 @@ int mscp_mkdir(const char *path, mode_t mode, sftp_session sftp)
return ret;
}


static void sftp_attr_to_stat(sftp_attributes attr, struct stat *st)
{
memset(st, 0, sizeof(*st));
st->st_size = attr->size;
st->st_uid = attr->uid;
st->st_gid = attr->gid;
st->st_mode = attr->permissions;
memset(st, 0, sizeof(*st));
st->st_size = attr->size;
st->st_uid = attr->uid;
st->st_gid = attr->gid;
st->st_mode = attr->permissions;

#if defined(__APPLE__)
#define st_atim st_atimespec
#define st_mtim st_mtimespec
#define st_ctim st_ctimespec
#define st_atim st_atimespec
#define st_mtim st_mtimespec
#define st_ctim st_ctimespec
#endif
st->st_atim.tv_sec = attr->atime;
st->st_atim.tv_nsec = attr->atime_nseconds;
st->st_mtim.tv_sec = attr->mtime;
st->st_mtim.tv_nsec = attr->mtime_nseconds;
st->st_ctim.tv_sec = attr->createtime;
st->st_ctim.tv_nsec = attr->createtime_nseconds;
st->st_atim.tv_sec = attr->atime;
st->st_atim.tv_nsec = attr->atime_nseconds;
st->st_mtim.tv_sec = attr->mtime;
st->st_mtim.tv_nsec = attr->mtime_nseconds;
st->st_ctim.tv_sec = attr->createtime;
st->st_ctim.tv_nsec = attr->createtime_nseconds;

switch (attr->type) {
case SSH_FILEXFER_TYPE_REGULAR:
Expand All @@ -203,7 +199,6 @@ static void sftp_attr_to_stat(sftp_attributes attr, struct stat *st)
}
}


int mscp_stat(const char *path, struct stat *st, sftp_session sftp)
{
sftp_attributes attr;
Expand Down Expand Up @@ -256,7 +251,6 @@ int mscp_lstat_wrapped(const char *path, struct stat *st)
return mscp_lstat(path, st, tls_sftp);
}


mf *mscp_open(const char *path, int flags, mode_t mode, sftp_session sftp)
{
mf *f;
Expand Down Expand Up @@ -316,7 +310,7 @@ int mscp_setstat(const char *path, struct stat *st, bool preserve_ts, sftp_sessi
memset(&attr, 0, sizeof(attr));
attr.permissions = st->st_mode;
attr.size = st->st_size;
attr.flags = (SSH_FILEXFER_ATTR_PERMISSIONS|SSH_FILEXFER_ATTR_SIZE);
attr.flags = (SSH_FILEXFER_ATTR_PERMISSIONS | SSH_FILEXFER_ATTR_SIZE);
if (preserve_ts) {
attr.atime = st->st_atim.tv_sec;
attr.atime_nseconds = st->st_atim.tv_nsec;
Expand Down Expand Up @@ -357,7 +351,7 @@ int mscp_glob(const char *pattern, int flags, glob_t *pglob, sftp_session sftp)
set_tls_sftp_session(sftp);
#if defined(__APPLE__) || defined(__FreeBSD__)
pglob->gl_opendir = (void *(*)(const char *))mscp_opendir_wrapped;
pglob->gl_readdir = (struct dirent *(*)(void *))mscp_readdir;
pglob->gl_readdir = (struct dirent * (*)(void *)) mscp_readdir;
pglob->gl_closedir = (void (*)(void *))mscp_closedir;
pglob->gl_lstat = mscp_lstat_wrapped;
pglob->gl_stat = mscp_stat_wrapped;
Expand Down
2 changes: 0 additions & 2 deletions src/fileops.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ struct mdir_struct {
};
typedef struct mdir_struct MDIR;


MDIR *mscp_opendir(const char *path, sftp_session sftp);
MDIR *mscp_opendir_wrapped(const char *path);
void mscp_closedir(MDIR *md);
Expand All @@ -34,7 +33,6 @@ int mscp_stat_wrapped(const char *path, struct stat *st);
int mscp_lstat(const char *path, struct stat *st, sftp_session sftp);
int mscp_lstat_wrapped(const char *path, struct stat *st);


/* file operations */

struct mf_struct {
Expand Down
Loading

0 comments on commit 93f155c

Please sign in to comment.