Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
htop
Commits
d1b1cbc7
Commit
d1b1cbc7
authored
13 years ago
by
Hisham Muhammad
Browse files
Options
Download
Email Patches
Plain Diff
cleanups and fixes, thanks to cppcheck and gcc -Wextra
parent
75080ce7
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
BatteryMeter.c
+5
-2
BatteryMeter.c
LoadAverageMeter.c
+1
-1
LoadAverageMeter.c
Makefile.am
+1
-1
Makefile.am
Meter.c
+1
-4
Meter.c
Object.c
+0
-6
Object.c
Process.c
+4
-4
Process.c
ProcessList.c
+8
-8
ProcessList.c
UptimeMeter.c
+1
-1
UptimeMeter.c
with
21 additions
and
27 deletions
+21
-27
BatteryMeter.c
View file @
d1b1cbc7
...
...
@@ -45,7 +45,7 @@ static unsigned long int parseUevent(FILE * file, const char *key) {
}
static
unsigned
long
int
parseBatInfo
(
const
char
*
fileName
,
const
unsigned
short
int
lineNum
,
const
unsigned
short
int
wordNum
)
{
const
DIR
*
batteryDir
;
DIR
*
batteryDir
;
const
struct
dirent
*
dirEntries
;
const
char
batteryPath
[]
=
PROCDIR
"/acpi/battery/"
;
...
...
@@ -89,6 +89,7 @@ static unsigned long int parseBatInfo(const char *fileName, const unsigned short
snprintf
((
char
*
)
infoPath
,
sizeof
infoPath
,
"%s%s/%s"
,
batteryPath
,
newEntry
->
content
,
fileName
);
if
((
file
=
fopen
(
infoPath
,
"r"
))
==
NULL
)
{
closedir
(
batteryDir
);
return
0
;
}
...
...
@@ -107,7 +108,7 @@ static unsigned long int parseBatInfo(const char *fileName, const unsigned short
free
(
myList
);
free
(
newEntry
);
closedir
(
(
DIR
*
)
batteryDir
);
closedir
(
batteryDir
);
return
total
;
}
...
...
@@ -274,6 +275,7 @@ static double getSysBatData() {
}
else
{
//reset file pointer
if
(
fseek
(
file
,
0
,
SEEK_SET
)
<
0
)
{
closedir
(
power_supplyDir
);
fclose
(
file
);
return
0
;
}
...
...
@@ -285,6 +287,7 @@ static double getSysBatData() {
}
else
{
//reset file pointer
if
(
fseek
(
file
,
0
,
SEEK_SET
)
<
0
)
{
closedir
(
power_supplyDir
);
fclose
(
file
);
return
0
;
}
...
...
This diff is collapsed.
Click to expand it.
LoadAverageMeter.c
View file @
d1b1cbc7
...
...
@@ -23,7 +23,7 @@ static inline void LoadAverageMeter_scan(double* one, double* five, double* fift
*
one
=
0
;
*
five
=
0
;
*
fifteen
=
0
;
FILE
*
fd
=
fopen
(
PROCDIR
"/loadavg"
,
"r"
);
if
(
fd
)
{
int
total
=
fscanf
(
fd
,
"%lf %lf %lf %d/%d %d"
,
one
,
five
,
fifteen
,
int
total
=
fscanf
(
fd
,
"%
32
lf %
32
lf %
32
lf %
32
d/%
32
d %
32
d"
,
one
,
five
,
fifteen
,
&
activeProcs
,
&
totalProcs
,
&
lastProc
);
(
void
)
total
;
assert
(
total
==
6
);
...
...
This diff is collapsed.
Click to expand it.
Makefile.am
View file @
d1b1cbc7
...
...
@@ -14,7 +14,7 @@ applications_DATA = htop.desktop
pixmapdir
=
$(datadir)
/pixmaps
pixmap_DATA
=
htop.png
htop_CFLAGS
=
-pedantic
-Wall
-std
=
c99
-rdynamic
-D_XOPEN_SOURCE_EXTENDED
htop_CFLAGS
=
-pedantic
-Wall
-Wextra
-std
=
c99
-rdynamic
-D_XOPEN_SOURCE_EXTENDED
AM_CFLAGS
=
AM_CPPFLAGS
=
-DSYSCONFDIR
=
\"
$(sysconfdir)
\"
...
...
This diff is collapsed.
Click to expand it.
Meter.c
View file @
d1b1cbc7
...
...
@@ -5,7 +5,6 @@ Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
*/
#define _GNU_SOURCE
#include "RichString.h"
#include "Meter.h"
#include "Object.h"
...
...
@@ -275,11 +274,10 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
for
(
int
i
=
0
;
i
<
w
;
i
++
)
bar
[
i
]
=
' '
;
const
size_t
barOffset
=
w
-
MIN
(
strlen
(
buffer
),
w
);
const
size_t
barOffset
=
w
-
MIN
(
(
int
)
strlen
(
buffer
),
w
);
snprintf
(
bar
+
barOffset
,
w
-
barOffset
+
1
,
"%s"
,
buffer
);
// First draw in the bar[] buffer...
double
total
=
0
.
0
;
int
offset
=
0
;
for
(
int
i
=
0
;
i
<
type
->
items
;
i
++
)
{
double
value
=
this
->
values
[
i
];
...
...
@@ -302,7 +300,6 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
}
}
offset
=
nextOffset
;
total
+=
this
->
values
[
i
];
}
// ...then print the buffer.
...
...
This diff is collapsed.
Click to expand it.
Object.c
View file @
d1b1cbc7
...
...
@@ -48,10 +48,4 @@ void Object_setClass(void* this, char* class) {
((
Object
*
)
this
)
->
class
=
class
;
}
static
void
Object_display
(
Object
*
this
,
RichString
*
out
)
{
char
objAddress
[
50
];
sprintf
(
objAddress
,
"%s @ %p"
,
this
->
class
,
(
void
*
)
this
);
RichString_write
(
out
,
CRT_colors
[
DEFAULT_COLOR
],
objAddress
);
}
#endif
This diff is collapsed.
Click to expand it.
Process.c
View file @
d1b1cbc7
...
...
@@ -235,7 +235,7 @@ void Process_getMaxPid() {
FILE
*
file
=
fopen
(
PROCDIR
"/sys/kernel/pid_max"
,
"r"
);
if
(
!
file
)
return
;
int
maxPid
=
4194303
;
fscanf
(
file
,
"%d"
,
&
maxPid
);
fscanf
(
file
,
"%
32
d"
,
&
maxPid
);
fclose
(
file
);
if
(
maxPid
>
99999
)
{
Process_fieldTitles
[
PID
]
=
" PID "
;
...
...
@@ -287,7 +287,7 @@ static void Process_humanNumber(Process* this, RichString* str, unsigned long nu
}
}
static
void
Process_colorNumber
(
Process
*
this
,
RichString
*
str
,
unsigned
long
long
number
)
{
static
void
Process_colorNumber
(
RichString
*
str
,
unsigned
long
long
number
)
{
char
buffer
[
14
];
if
(
number
>
10000000000
)
{
snprintf
(
buffer
,
13
,
"%11lld "
,
number
/
1000
);
...
...
@@ -486,8 +486,8 @@ static void Process_writeField(Process* this, RichString* str, ProcessField fiel
case
WCHAR
:
snprintf
(
buffer
,
n
,
"%12llu "
,
this
->
io_wchar
);
break
;
case
SYSCR
:
snprintf
(
buffer
,
n
,
"%10llu "
,
this
->
io_syscr
);
break
;
case
SYSCW
:
snprintf
(
buffer
,
n
,
"%10llu "
,
this
->
io_syscw
);
break
;
case
RBYTES
:
Process_colorNumber
(
this
,
str
,
this
->
io_read_bytes
);
return
;
case
WBYTES
:
Process_colorNumber
(
this
,
str
,
this
->
io_write_bytes
);
return
;
case
RBYTES
:
Process_colorNumber
(
str
,
this
->
io_read_bytes
);
return
;
case
WBYTES
:
Process_colorNumber
(
str
,
this
->
io_write_bytes
);
return
;
case
CNCLWB
:
snprintf
(
buffer
,
n
,
"%10llu "
,
this
->
io_cancelled_write_bytes
);
break
;
case
IO_READ_RATE
:
Process_outputRate
(
this
,
str
,
attr
,
buffer
,
n
,
this
->
io_rate_read_bps
);
return
;
case
IO_WRITE_RATE
:
Process_outputRate
(
this
,
str
,
attr
,
buffer
,
n
,
this
->
io_rate_write_bps
);
return
;
...
...
This diff is collapsed.
Click to expand it.
ProcessList.c
View file @
d1b1cbc7
...
...
@@ -438,7 +438,7 @@ static bool ProcessList_readStatmFile(Process* process, const char* dirname, con
if
(
!
file
)
return
false
;
int
num
=
fscanf
(
file
,
"%d %d %d %d %d %d %d"
,
int
num
=
fscanf
(
file
,
"%
32
d %
32
d %
32
d %
32
d %
32
d %
32
d %
32
d"
,
&
process
->
m_size
,
&
process
->
m_resident
,
&
process
->
m_share
,
&
process
->
m_trs
,
&
process
->
m_lrs
,
&
process
->
m_drs
,
&
process
->
m_dt
);
...
...
@@ -460,13 +460,13 @@ static void ProcessList_readOpenVZData(Process* process, const char* dirname, co
if
(
!
file
)
return
;
fscanf
(
file
,
"%*u %*s %*c %*u %*u %*u %*u %*u %*u %*u "
"%*u %*u %*u %*u %*u %*u %*u %*u "
"%*u %*u %*u %*u %*u %*u %*u %*u "
"%*u %*u %*u %*u %*u %*u %*u %*u "
"%*u %*u %*u %*u %*u %*u %*u %*u "
"%*u %*u %*u %*u %*u %*u %*u "
"%*u %*u %u %u"
,
"%*
32
u %*
32
s %*
1
c %*
32
u %*
32
u %*
32
u %*
32
u %*
32
u %*
32
u %*
32
u "
"%*
32
u %*
32
u %*
32
u %*
32
u %*
32
u %*
32
u %*
32
u %*
32
u "
"%*
32
u %*
32
u %*
32
u %*
32
u %*
32
u %*
32
u %*
32
u %*
32
u "
"%*
32
u %*
32
u %*
32
u %*
32
u %*
32
u %*
32
u %*
32
u %*
32
u "
"%*
32
u %*
32
u %*
32
u %*
32
u %*
32
u %*
32
u %*
32
u %*
32
u "
"%*
32
u %*
32
u %*
32
u %*
32
u %*
32
u %*
32
u %*
32
u "
"%*
32
u %*
32
u %
32
u %
32
u"
,
&
process
->
vpid
,
&
process
->
ctid
);
fclose
(
file
);
}
...
...
This diff is collapsed.
Click to expand it.
UptimeMeter.c
View file @
d1b1cbc7
...
...
@@ -22,7 +22,7 @@ static void UptimeMeter_setValues(Meter* this, char* buffer, int len) {
double
uptime
=
0
;
FILE
*
fd
=
fopen
(
PROCDIR
"/uptime"
,
"r"
);
if
(
fd
)
{
fscanf
(
fd
,
"%lf"
,
&
uptime
);
fscanf
(
fd
,
"%
64
lf"
,
&
uptime
);
fclose
(
fd
);
}
int
totalseconds
=
(
int
)
ceil
(
uptime
);
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment