Refactor atoi
Co-authored-by: Ezequiel Bellver <ebellver@itba.edu.ar> Co-authored-by: Juan Barmasch <jbarmasch@itba.edu.ar>
This commit is contained in:
parent
c4714fe772
commit
730145a7c8
|
@ -12,7 +12,7 @@ void backspace();
|
|||
char getChar();
|
||||
void putChar(char c);
|
||||
int abs();
|
||||
int atoi(char * buffer, int len);
|
||||
int atoi(char * buffer);
|
||||
int strlen(const char * s);
|
||||
void scanf(char * buffer, int maxLen);
|
||||
int strcmp(const char * s1, const char * s2);
|
||||
|
|
|
@ -153,7 +153,7 @@ char *itoa(int value, char *buffer, int base) {
|
|||
return reverse(buffer, 0, i - 1);
|
||||
}
|
||||
|
||||
int atoi(char *str, int length) {
|
||||
int atoi(char *str) {
|
||||
int i = 0, sign = 1, val = 0;
|
||||
while (str[i] != '\0') {
|
||||
if (str[i] == '-') {
|
||||
|
|
|
@ -8,7 +8,7 @@ void block(int argc, char ** argv) {
|
|||
// sys_exit();
|
||||
return;
|
||||
}
|
||||
int pid = atoi(argv[1], MAX_LEN);
|
||||
int pid = atoi(argv[1]);
|
||||
|
||||
sys_block(pid);
|
||||
// sys_exit();
|
||||
|
|
|
@ -22,7 +22,7 @@ void help(int argc, char *argv[]) {
|
|||
sys_exit();
|
||||
}
|
||||
|
||||
int page = atoi(argv[1], 10);
|
||||
int page = atoi(argv[1]);
|
||||
int pages = getCurrentPages();
|
||||
|
||||
if (page < 1 || page > pages) {
|
||||
|
|
|
@ -8,7 +8,7 @@ void kill(int argc, char ** argv) {
|
|||
// sys_exit();
|
||||
return;
|
||||
}
|
||||
int pid = atoi(argv[1], MAX_LEN);
|
||||
int pid = atoi(argv[1]);
|
||||
|
||||
sys_kill(pid);
|
||||
// sys_exit();
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include "loop.h"
|
||||
#define PUAN -1
|
||||
|
||||
void loop(int argc, char *argv[]) {
|
||||
if (argc != 3) {
|
||||
printStringLen("loop receives an amount of seconds and a text\n", 47);
|
||||
sys_exit();
|
||||
}
|
||||
int pid = sys_getPid(), secs = atoi(argv[1], PUAN);
|
||||
int pid = sys_getPid(), secs = atoi(argv[1]);
|
||||
char * str = argv[2];
|
||||
char * buffer = sys_malloc(MAX_PID_LEN);
|
||||
buffer = strcat(strcat(itoa(pid, buffer, 10), " "), str);
|
||||
|
|
|
@ -7,8 +7,8 @@ void nice(int argc, char ** argv) {
|
|||
printStringLen("nice receives a pid and an offset\n", 35);
|
||||
sys_exit();
|
||||
}
|
||||
int pid = atoi(argv[1], MAX_LEN);
|
||||
char offset = (char) atoi(argv[2], MAX_LEN);
|
||||
int pid = atoi(argv[1]);
|
||||
char offset = (char) atoi(argv[2]);
|
||||
|
||||
sys_nice(pid, offset);
|
||||
sys_exit();
|
||||
|
|
|
@ -33,6 +33,7 @@ void addPhilo() {
|
|||
new->buffer = sys_malloc(sizeof(char) * BUFF_SIZE);
|
||||
new->state = THINKING;
|
||||
char * aux = sys_malloc(sizeof(char) * 20);
|
||||
aux[0] = '\0';
|
||||
aux = strcat(aux, "filosofo");
|
||||
char buffer[2] = {0};
|
||||
aux = strcat(aux, itoa(philoCount, buffer, 10));
|
||||
|
@ -93,7 +94,7 @@ void philosopher(int argc, char ** argv) {
|
|||
sys_exit();
|
||||
}
|
||||
|
||||
philosopher_t * i = (philosopher_t *) ((uint64_t) atoi(argv[1], -1));
|
||||
philosopher_t * i = (philosopher_t *) ((uint64_t) atoi(argv[1]));
|
||||
|
||||
while (1) {
|
||||
sys_sleep(1);
|
||||
|
@ -113,7 +114,7 @@ void phylo(int argc, char ** argv) {
|
|||
if (argc == 1)
|
||||
philoCount = STARTING;
|
||||
else if (argc == 2) {
|
||||
philoCount = atoi(argv[1], -1);
|
||||
philoCount = atoi(argv[1]);
|
||||
if (philoCount < 1 || philoCount > MAX_PHILO_SIZE) {
|
||||
printStringLen("amount of philosofers must be between 1 and 10\n", 48);
|
||||
sys_exit();
|
||||
|
@ -130,6 +131,7 @@ void phylo(int argc, char ** argv) {
|
|||
phil->buffer = sys_malloc(20);
|
||||
phil->state = THINKING;
|
||||
char * aux = sys_malloc(sizeof(char) * 20);
|
||||
aux[0] = '\0';
|
||||
aux = strcat(aux, "filosofo");
|
||||
char buffer[2] = {0};
|
||||
aux = strcat(aux, itoa(i, buffer, 10));
|
||||
|
@ -173,9 +175,6 @@ void phylo(int argc, char ** argv) {
|
|||
else if (c == 'q') {
|
||||
end();
|
||||
}
|
||||
// else {
|
||||
// end();
|
||||
// }
|
||||
}
|
||||
sys_exit();
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ void printmem(int argc, char *argv[]) {
|
|||
|
||||
int buffer[8];
|
||||
|
||||
getMem(buffer, atoi(argv[1], strlen(argv[1])));
|
||||
getMem(buffer, atoi(argv[1]));
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
char bufferAux[8];
|
||||
|
|
|
@ -22,9 +22,9 @@ void inc(int argc, char ** argv) {
|
|||
return;
|
||||
}
|
||||
|
||||
uint64_t semDir = (uint64_t) atoi(argv[1], 14);
|
||||
int64_t value = atoi(argv[2], 10);
|
||||
uint64_t N = atoi(argv[3], 10);
|
||||
uint64_t semDir = (uint64_t) atoi(argv[1]);
|
||||
int64_t value = atoi(argv[2]);
|
||||
uint64_t N = atoi(argv[3]);
|
||||
uint64_t i;
|
||||
|
||||
for (i = 0; i < N; i++){
|
||||
|
|
|
@ -7,7 +7,7 @@ void unblock(int argc, char ** argv) {
|
|||
printStringLen("unblock receives a pid\n", 21);
|
||||
sys_exit();
|
||||
}
|
||||
int pid = atoi(argv[1], MAX_LEN);
|
||||
int pid = atoi(argv[1]);
|
||||
|
||||
sys_unblock(pid);
|
||||
sys_exit();
|
||||
|
|
Loading…
Reference in New Issue