[Libreoffice-commits] online.git: 2 commits - loolwsd/loolmap.c
Tor Lillqvist
tml at collabora.com
Fri Oct 14 10:10:41 UTC 2016
loolwsd/loolmap.c | 253 +++++++++++++++++++++++++++---------------------------
1 file changed, 131 insertions(+), 122 deletions(-)
New commits:
commit 3757125b23a59568a70e8c24f168486f6544d245
Author: Tor Lillqvist <tml at collabora.com>
Date: Fri Oct 14 13:09:02 2016 +0300
Use same indentation and whitespace style as in other source files
Only whitespace changes in this commit.
diff --git a/loolwsd/loolmap.c b/loolwsd/loolmap.c
index 53d18bc..c455a14 100644
--- a/loolwsd/loolmap.c
+++ b/loolwsd/loolmap.c
@@ -22,157 +22,157 @@
#define PATH_SIZE 64
#define BUFFER_SIZE 9600
-static int read_buffer( char *buffer, unsigned size,
- const char *file, char sep )
+static int read_buffer(char *buffer, unsigned size,
+ const char *file, char sep)
{
- int file_desc;
- unsigned total_bytes = 0;
-
- file_desc = open(file, O_RDONLY);
- if(file_desc == -1)
- return 0;
-
- for(;;)
- {
- ssize_t number_bytes = read( file_desc,
- buffer + total_bytes,
- size - total_bytes );
- if(number_bytes == -1)
- {
- if(errno==EINTR)
- continue;
- break;
- }
+ int file_desc;
+ unsigned total_bytes = 0;
- total_bytes += number_bytes;
- if(total_bytes == size)
+ file_desc = open(file, O_RDONLY);
+ if (file_desc == -1)
+ return 0;
+
+ for (;;)
{
- --total_bytes;
- break;
- }
+ ssize_t number_bytes = read(file_desc,
+ buffer + total_bytes,
+ size - total_bytes);
+ if (number_bytes == -1)
+ {
+ if (errno==EINTR)
+ continue;
+ break;
+ }
- if(number_bytes==0)
- break; // EOF
- }
+ total_bytes += number_bytes;
+ if (total_bytes == size)
+ {
+ --total_bytes;
+ break;
+ }
+
+ if (number_bytes==0)
+ break; // EOF
+ }
- close(file_desc);
+ close(file_desc);
- if(total_bytes)
- {
- int i=total_bytes;
+ if (total_bytes)
+ {
+ int i=total_bytes;
- while(i--)
- if(buffer[i]=='\n' || buffer[i]=='\0')
- buffer[i]=sep;
+ while (i--)
+ if (buffer[i]=='\n' || buffer[i]=='\0')
+ buffer[i]=sep;
- if(buffer[total_bytes-1]==' ')
- buffer[total_bytes-1]='\0';
- }
+ if (buffer[total_bytes-1]==' ')
+ buffer[total_bytes-1]='\0';
+ }
- buffer[total_bytes] = '\0';
- return total_bytes;
+ buffer[total_bytes] = '\0';
+ return total_bytes;
}
static void total_smaps(unsigned proc_id, const char *file, const char *cmdline)
{
- FILE *file_pointer;
- char buffer[BUFFER_SIZE];
-
- unsigned long long total_private_dirty = 0ull;
- unsigned long long total_private_clean = 0ull;
- unsigned long long total_shared_dirty = 0ull;
- unsigned long long total_shared_clean = 0ull;
- unsigned long long smap_value;
- char smap_key[MAP_SIZE];
-
- if ((file_pointer = fopen(file, "r")) == NULL)
- error(EXIT_FAILURE, errno, "%s", file);
-
- while (fgets(buffer, sizeof(buffer), file_pointer))
- {
- if (buffer[0] >= 'A' && buffer[0] <= 'Z')
+ FILE *file_pointer;
+ char buffer[BUFFER_SIZE];
+
+ unsigned long long total_private_dirty = 0ull;
+ unsigned long long total_private_clean = 0ull;
+ unsigned long long total_shared_dirty = 0ull;
+ unsigned long long total_shared_clean = 0ull;
+ unsigned long long smap_value;
+ char smap_key[MAP_SIZE];
+
+ if ((file_pointer = fopen(file, "r")) == NULL)
+ error(EXIT_FAILURE, errno, "%s", file);
+
+ while (fgets(buffer, sizeof(buffer), file_pointer))
{
- if (sscanf(buffer, "%20[^:]: %llu", smap_key, &smap_value) == 2)
- {
- if (strncmp("Shared_Dirty", smap_key, 12) == 0)
- {
- total_shared_dirty += smap_value;
- continue;
- }
- if (strncmp("Shared_Clean", smap_key, 12) == 0)
+ if (buffer[0] >= 'A' && buffer[0] <= 'Z')
{
- total_shared_clean += smap_value;
- continue;
+ if (sscanf(buffer, "%20[^:]: %llu", smap_key, &smap_value) == 2)
+ {
+ if (strncmp("Shared_Dirty", smap_key, 12) == 0)
+ {
+ total_shared_dirty += smap_value;
+ continue;
+ }
+ if (strncmp("Shared_Clean", smap_key, 12) == 0)
+ {
+ total_shared_clean += smap_value;
+ continue;
+ }
+ if (strncmp("Private_Dirty", smap_key, 13) == 0)
+ {
+ total_private_dirty += smap_value;
+ continue;
+ }
+ if (strncmp("Private_Clean", smap_key, 13) == 0)
+ {
+ total_private_clean += smap_value;
+ continue;
+ }
+ }
}
- if (strncmp("Private_Dirty", smap_key, 13) == 0)
- {
- total_private_dirty += smap_value;
- continue;
- }
- if (strncmp("Private_Clean", smap_key, 13) == 0)
- {
- total_private_clean += smap_value;
- continue;
- }
- }
}
- }
-
- if ( errno )
- error(EXIT_FAILURE, errno, "%s\n", cmdline);
-
- printf("%s\n", cmdline);
- printf("Process ID :%20d\n", proc_id);
- printf("--------------------------------------\n");
- printf("Shared Clean :%20lld kB\n", total_shared_clean);
- printf("Shared Dirty :%20lld kB\n", total_shared_dirty);
- printf("Private Clean :%20lld kB\n", total_private_clean);
- printf("Private Dirty :%20lld kB\n", total_private_dirty);
- printf("--------------------------------------\n");
- printf("Shared :%20lld kB\n", total_shared_clean + total_shared_dirty);
- printf("Private :%20lld kB\n\n", total_private_clean + total_private_dirty);
+
+ if (errno)
+ error(EXIT_FAILURE, errno, "%s\n", cmdline);
+
+ printf("%s\n", cmdline);
+ printf("Process ID :%20d\n", proc_id);
+ printf("--------------------------------------\n");
+ printf("Shared Clean :%20lld kB\n", total_shared_clean);
+ printf("Shared Dirty :%20lld kB\n", total_shared_dirty);
+ printf("Private Clean :%20lld kB\n", total_private_clean);
+ printf("Private Dirty :%20lld kB\n", total_private_dirty);
+ printf("--------------------------------------\n");
+ printf("Shared :%20lld kB\n", total_shared_clean + total_shared_dirty);
+ printf("Private :%20lld kB\n\n", total_private_clean + total_private_dirty);
}
int main(int argc, char **argv)
{
- DIR *root_proc;
- struct dirent *dir_proc;
-
- unsigned pid_proc;
- char path_proc[PATH_SIZE];
- char cmdline[BUFFER_SIZE];
+ DIR *root_proc;
+ struct dirent *dir_proc;
- setlocale (LC_ALL, "");
- getopt(argc, argv, "");
+ unsigned pid_proc;
+ char path_proc[PATH_SIZE];
+ char cmdline[BUFFER_SIZE];
- if (argc != 2)
- error(EXIT_FAILURE, EINVAL, "incorrect arguments");
+ setlocale (LC_ALL, "");
+ getopt(argc, argv, "");
- root_proc = opendir("/proc");
- if (!root_proc)
- error(EXIT_FAILURE, errno, "%s", "/proc");
+ if (argc != 2)
+ error(EXIT_FAILURE, EINVAL, "incorrect arguments");
- while ( ( dir_proc = readdir(root_proc) ) )
- {
- if ( !dir_proc && !dir_proc->d_name[0] )
- error(EXIT_FAILURE, ENOTDIR, "bad dir");
+ root_proc = opendir("/proc");
+ if (!root_proc)
+ error(EXIT_FAILURE, errno, "%s", "/proc");
- if ( *dir_proc->d_name > '0' && *dir_proc->d_name <= '9' )
+ while ((dir_proc = readdir(root_proc)))
{
- pid_proc = strtoul(dir_proc->d_name, NULL, 10);
- snprintf(path_proc, sizeof(path_proc), "/proc/%s/%s", dir_proc->d_name, "cmdline");
- if (read_buffer(cmdline, sizeof(cmdline), path_proc, ' ') &&
- strstr(cmdline, argv[1]) &&
- !strstr(cmdline, argv[0]) )
- {
- snprintf(path_proc, sizeof(path_proc), "/proc/%s/%s", dir_proc->d_name, "smaps");
- total_smaps(pid_proc, path_proc, cmdline);
- }
+ if (!dir_proc && !dir_proc->d_name[0])
+ error(EXIT_FAILURE, ENOTDIR, "bad dir");
+
+ if (*dir_proc->d_name > '0' && *dir_proc->d_name <= '9')
+ {
+ pid_proc = strtoul(dir_proc->d_name, NULL, 10);
+ snprintf(path_proc, sizeof(path_proc), "/proc/%s/%s", dir_proc->d_name, "cmdline");
+ if (read_buffer(cmdline, sizeof(cmdline), path_proc, ' ') &&
+ strstr(cmdline, argv[1]) &&
+ !strstr(cmdline, argv[0]))
+ {
+ snprintf(path_proc, sizeof(path_proc), "/proc/%s/%s", dir_proc->d_name, "smaps");
+ total_smaps(pid_proc, path_proc, cmdline);
+ }
+ }
}
- }
- if ( errno )
- error(EXIT_FAILURE, errno, "fail");
+ if (errno)
+ error(EXIT_FAILURE, errno, "fail");
return EXIT_SUCCESS;
}
commit c628b00c3ea26dc2b99c681e95f88e4971f1f173
Author: Tor Lillqvist <tml at collabora.com>
Date: Fri Oct 14 13:05:09 2016 +0300
Add Emacs mode line and license blurb here, too
diff --git a/loolwsd/loolmap.c b/loolwsd/loolmap.c
index 3a863ae..53d18bc 100644
--- a/loolwsd/loolmap.c
+++ b/loolwsd/loolmap.c
@@ -1,3 +1,12 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
#include <string.h>
#include <ctype.h>
#include <errno.h>
More information about the Libreoffice-commits
mailing list