Changeset 74c69dc in mainline for uspace/app/cmpdirs/cmpdirs.c


Ignore:
Timestamp:
2026-03-17T12:43:08Z (28 hours ago)
Author:
Vít Skalický <skalicky@…>
Children:
4a0bfcf0
Parents:
b017885
Message:

Fix code style

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/cmpdirs/cmpdirs.c

    rb017885 r74c69dc  
    6464/** Returns true if all directories and files in the filesystem tree of handle1 also exist in the filesystem tree of
    6565 * handle2 and in reverse and all their contents and metadata is equal.
    66  * hande1 and handle2 are handles to a directory (or file). */
    67 static errno_t trees_equal(int handle1, int handle2, bool* equal_out);
     66 * hande1 and handle2 are handles to a directory (or file).
     67 */
     68static errno_t trees_equal(int handle1, int handle2, bool *equal_out);
    6869
    6970int main(int argc, char *argv[])
     
    109110        // initialize logging
    110111        rc = log_init(NAME);
    111         if (rc != EOK) goto close_end;
     112        if (rc != EOK)
     113                goto close_end;
    112114        logctl_set_log_level(NAME, LVL_DEBUG2);
    113115
     
    124126        bool equal;
    125127        rc = trees_equal(handle1, handle2, &equal);
    126         if (rc != EOK) goto close2;
     128        if (rc != EOK)
     129                goto close2;
    127130close2:
    128131        vfs_put(handle2);
     
    132135
    133136        if (rc != EOK) {
    134                 fprintf(stderr, "%d\n",rc);
     137                fprintf(stderr, "%d\n", rc);
    135138                fprintf(stderr, "An error occurred: %s: %s\n", str_error_name(rc), str_error(rc));
    136139                return 2;
     
    159162
    160163/** Create a new growable stack. Don't forget to free it using stack_free when you are done using it. */
    161 static errno_t stack_new(struct stack* s) {
     164static errno_t stack_new(struct stack *s)
     165{
    162166        s->size = 0;
    163167        s->capacity = STACK_INIT_CAPACITY;
     
    170174
    171175/** Destroy a growable stack and free its memory */
    172 static void stack_free(struct stack* s) {
     176static void stack_free(struct stack *s)
     177{
    173178        if (s->buffer != NULL) {
    174179                free(s->buffer);
     
    180185
    181186/** Append an entry to the stack. Allocates larger memory if needed. */
    182 static errno_t stack_append(struct stack *s, struct entry e) {
     187static errno_t stack_append(struct stack *s, struct entry e)
     188{
    183189        if (s->capacity == 0 || s->buffer == NULL) {
    184190                // stack has already been freed before
     
    204210
    205211/** Returns the last entry in the stack and removes it from it. Does not free any memory. */
    206 static errno_t stack_pop(struct stack *s, struct entry *entry_out) {
     212static errno_t stack_pop(struct stack *s, struct entry *entry_out)
     213{
    207214        if (s->size == 0) {
    208215                return EEMPTY;
     
    214221
    215222/** Compares two vfs_stat_t structures in the sense that they represent the same data possibly across different filesystems. */
    216 static bool stat_equal(vfs_stat_t a, vfs_stat_t b) {
     223static bool stat_equal(vfs_stat_t a, vfs_stat_t b)
     224{
    217225        return a.is_file == b.is_file &&
    218                 a.is_directory == b.is_directory &&
    219                 a.size == b.size;
     226            a.is_directory == b.is_directory &&
     227            a.size == b.size;
    220228}
    221229
     
    224232 *  - both files have the same size
    225233 *  - both buffers are the size CHUNK_SIZE
    226  *  - both handles are open for reading */
    227 static errno_t content_equal(int handle1, vfs_stat_t stat1, char* buffer1, int handle2, vfs_stat_t stat2, char* buffer2, bool *equal_out) {
     234 *  - both handles are open for reading
     235 */
     236static errno_t content_equal(int handle1, vfs_stat_t stat1, char *buffer1, int handle2, vfs_stat_t stat2, char *buffer2, bool *equal_out)
     237{
    228238        errno_t rc = EOK;
    229239        bool equal = true;
     
    254264}
    255265
    256 static errno_t trees_equal(int root_handle1, int root_handle2, bool* equal_out) {
     266static errno_t trees_equal(int root_handle1, int root_handle2, bool *equal_out)
     267{
    257268        // todo Check once again that all file handles are put at the end
    258269        // Performs a depth-first search on handle1 and compares it to handle2.
     
    269280
    270281        char *file_buffer1 = malloc(CHUNK_SIZE);
    271         if (file_buffer1 == NULL) rc = ENOMEM;
     282        if (file_buffer1 == NULL)
     283                rc = ENOMEM;
    272284        check_ok(rc, close1, "No memory for file buffer #1 (%d bytes needed)\n", CHUNK_SIZE);
    273285
    274286        char *file_buffer2 = malloc(CHUNK_SIZE);
    275         if (file_buffer2 == NULL) rc = ENOMEM;
     287        if (file_buffer2 == NULL)
     288                rc = ENOMEM;
    276289        check_ok(rc, close2, "No memory for file buffer #2 (%d bytes needed)\n", CHUNK_SIZE);
    277290
    278291        // While there is something in the stack
    279         for (struct entry item = {root_handle1, root_handle2}; // initial item
    280                 rc != EEMPTY; // was pop successful?
    281                 rc = stack_pop(&s, &item)
    282                 ) {
     292        for (struct entry item = { root_handle1, root_handle2 }; // initial item
     293            rc != EEMPTY; // was pop successful?
     294            rc = stack_pop(&s, &item)) {
    283295                if (rc != EOK) {
    284296                        // other error than EEMPTY
     
    315327                        bool equal2;
    316328                        rc = content_equal(item.handle1, stat1, file_buffer1, item.handle2, stat2, file_buffer2, &equal2);
    317                         if (rc != EOK) goto close_inner;
     329                        if (rc != EOK)
     330                                goto close_inner;
    318331                        equal = equal && equal2;
    319                 }else {
     332                } else {
    320333                        // check directory listing and add its items to the stack
    321334
     
    344357                                        rc = ENAMETOOLONG;
    345358                                }
    346                                 check_ok_break(rc, "Name too long (limit is %"PRIdn" excluding null-terminator)", name_buffer_size);
     359                                check_ok_break(rc, "Name too long (limit is %" PRIdn " excluding null-terminator)", name_buffer_size);
    347360                                // add slash to the beginning of the name, because vfs_walk requires the path to be absolute (will be
    348361                                // resolved relatively to the starting directory)
    349                                 char name_with_slash[name_buffer_size+1];
     362                                char name_with_slash[name_buffer_size + 1];
    350363                                name_with_slash[0] = '/';
    351364                                str_cpy(name_with_slash + 1, name_size + 1, dp->d_name);
     
    356369                                // 3.
    357370                                int entry_handle2; // must be put
    358                                 rc= vfs_walk(item.handle2, name_with_slash, 0, &entry_handle2);
     371                                rc = vfs_walk(item.handle2, name_with_slash, 0, &entry_handle2);
    359372                                if (rc != EOK) {
    360373                                        errno_t rc2 = vfs_put(entry_handle1);
     
    369382
    370383                                // 4.
    371                                 struct entry newitem = {entry_handle1, entry_handle2};
     384                                struct entry newitem = { entry_handle1, entry_handle2 };
    372385                                rc = stack_append(&s, newitem);
    373386                                if (rc != EOK) {
     
    380393                        }
    381394                        closedir(dirp);
    382                         if (rc != EOK) goto close_inner;
     395                        if (rc != EOK)
     396                                goto close_inner;
    383397                }
    384398
     
    392406                        (void) rc2; // if put failed, I guess there is nothing I can do about it
    393407                }
    394                 if (rc != EOK) goto close_start;
    395                 if (!equal) break;
     408                if (rc != EOK)
     409                        goto close_start;
     410                if (!equal)
     411                        break;
    396412        }
    397413        assert(rc == EEMPTY || !equal);
     
    404420close1:
    405421        (void) 0; // Clangd is not happy about declaration right after a label, so here is a dummy statement.
    406         struct entry item = {};
     422        struct entry item = { };
    407423        for (errno_t for_rc = stack_pop(&s, &item);
    408                 for_rc != EEMPTY; // was pop successful?
    409                 for_rc = stack_pop(&s, &item)){
    410                         errno_t rc2 = vfs_put(item.handle1);
    411                         (void) rc2; // if put failed, I guess there is nothing I can do about it
    412                         rc2 = vfs_put(item.handle2);
    413                         (void) rc2; // if put failed, I guess there is nothing I can do about it
     424            for_rc != EEMPTY; // was pop successful?
     425            for_rc = stack_pop(&s, &item)) {
     426                errno_t rc2 = vfs_put(item.handle1);
     427                (void) rc2; // if put failed, I guess there is nothing I can do about it
     428                rc2 = vfs_put(item.handle2);
     429                (void) rc2; // if put failed, I guess there is nothing I can do about it
    414430        }
    415431
    416432        stack_free(&s);
    417433close_end:
    418         if (rc == EOK) *equal_out = equal;
     434        if (rc == EOK)
     435                *equal_out = equal;
    419436        return rc;
    420437}
    421 
    422438
    423439static void print_usage(void)
Note: See TracChangeset for help on using the changeset viewer.