Skip to content

Commit

Permalink
c
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Sep 26, 2014
1 parent 4d415c6 commit d8443b8
Show file tree
Hide file tree
Showing 97 changed files with 160 additions and 23 deletions.
3 changes: 2 additions & 1 deletion ft_atoi.c
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
/* ************************************************************************** */

#include "libft.h"
#include <limits.h>

static int ft_isspace(int c)
{
Expand All @@ -25,7 +26,7 @@ long ft_atol(const char *str)
number = 0;
if (ft_strncmp(str, "-9223372036854775808", 20) == 0
&& (str[20] < '0' || str[20] > '9'))
return (-9223372036854775807 - 1);
return (LONG_MIN);
while (ft_isspace(*str))
++str;
sign = (*str == '-') ? -1 : 1;
Expand Down
Empty file modified ft_atoi_base.c
100644 → 100755
Empty file.
Empty file modified ft_btree.c
100644 → 100755
Empty file.
Empty file modified ft_btree_put.c
100644 → 100755
Empty file.
Empty file modified ft_bzero.c
100644 → 100755
Empty file.
Empty file modified ft_getchar.c
100644 → 100755
Empty file.
Empty file modified ft_isalnum.c
100644 → 100755
Empty file.
Empty file modified ft_isalpha.c
100644 → 100755
Empty file.
Empty file modified ft_isascii.c
100644 → 100755
Empty file.
Empty file modified ft_isdigit.c
100644 → 100755
Empty file.
Empty file modified ft_isprint.c
100644 → 100755
Empty file.
Empty file modified ft_itoa.c
100644 → 100755
Empty file.
Empty file modified ft_ldcd_celldel.c
100644 → 100755
Empty file.
Empty file modified ft_ldcd_cellnew.c
100644 → 100755
Empty file.
Empty file modified ft_ldcdat.c
100644 → 100755
Empty file.
Empty file modified ft_ldcddel.c
100644 → 100755
Empty file.
Empty file modified ft_ldcddel_head.c
100644 → 100755
Empty file.
Empty file modified ft_ldcddel_tail.c
100644 → 100755
Empty file.
Empty file modified ft_ldcditer.c
100644 → 100755
Empty file.
Empty file modified ft_ldcdnew.c
100644 → 100755
Empty file.
Empty file modified ft_ldcdpop.c
100644 → 100755
Empty file.
Empty file modified ft_ldcdpop_back.c
100644 → 100755
Empty file.
Empty file modified ft_ldcdpop_front.c
100644 → 100755
Empty file.
Empty file modified ft_ldcdpush_back.c
100644 → 100755
Empty file.
Empty file modified ft_ldcdpush_front.c
100644 → 100755
Empty file.
Empty file modified ft_ldcdsize.c
100644 → 100755
Empty file.
Empty file modified ft_ldcdsize_ref.c
100644 → 100755
Empty file.
Empty file modified ft_lstadd.c
100644 → 100755
Empty file.
Empty file modified ft_lstdel.c
100644 → 100755
Empty file.
Empty file modified ft_lstdelone.c
100644 → 100755
Empty file.
Empty file modified ft_lstiter.c
100644 → 100755
Empty file.
Empty file modified ft_lstmap.c
100644 → 100755
Empty file.
Empty file modified ft_lstnew.c
100644 → 100755
Empty file.
Empty file modified ft_lstsize.c
100644 → 100755
Empty file.
Empty file modified ft_lsttotab.c
100644 → 100755
Empty file.
Empty file modified ft_memalloc.c
100644 → 100755
Empty file.
Empty file modified ft_memccpy.c
100644 → 100755
Empty file.
Empty file modified ft_memchr.c
100644 → 100755
Empty file.
Empty file modified ft_memcmp.c
100644 → 100755
Empty file.
Empty file modified ft_memcpy.c
100644 → 100755
Empty file.
Empty file modified ft_memdel.c
100644 → 100755
Empty file.
Empty file modified ft_memmove.c
100644 → 100755
Empty file.
Empty file modified ft_memset.c
100644 → 100755
Empty file.
6 changes: 3 additions & 3 deletions ft_print_memory.c
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#include "libft.h"

extern const char *g_hexbase;
static const char *g_hexbase = "0123456789abcdef";

static void ft_fill(int count, int space)
{
Expand Down Expand Up @@ -52,7 +52,7 @@ static void ft_putnstr(char *str, unsigned int len, int hex, int space)

static void ft_putline(char *addr, unsigned int offset, unsigned int size)
{
ft_putnbrhex(offset, 0);
ft_putnbrhex(offset, 8, 0);
ft_putchar(':');
ft_putchar('\t');
ft_putnstr(addr + offset, size, 1, 2);
Expand All @@ -66,7 +66,7 @@ void *ft_print_memory(void *addr, unsigned int size)
unsigned int count;

count = 0;
while (size - 16 > count)
while (size - 16 > count && size - 16 > 0)
{
ft_putline(addr, count, 16);
count += 16;
Expand Down
4 changes: 2 additions & 2 deletions ft_putchar.c
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#include <unistd.h>

void ft_putchar(char c)
int ft_putchar(char c)
{
write(1, &c, 1);
return (write(1, &c, 1));
}
Empty file modified ft_putchar_fd.c
100644 → 100755
Empty file.
56 changes: 56 additions & 0 deletions ft_putdouble.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include <unistd.h>
#include "libft.h"

//TODO: width specifier,fill char

static int ft_printradix(double nb, int prec)
{
char digit;
int size;

size = prec + 1;
write(1, ".", 1);
while (prec > 0)
{
if (nb != 0)
{
nb *= 10;
digit = (char)nb;
nb -= (double)digit;
ft_putchar(digit + '0');
}
else
ft_putchar('0');
--prec;
}
return (size);
}

int ft_putdouble(double nb, int prec)
{
int size;
double mask;
char digit;

size = 0;
mask = 1.0;
if (nb < 0)
{
nb = 0 - nb;
write(1, "-", 1);
++size;
}
while (nb / mask > 10.0)
mask *= 10.0;
while (mask >= 1.0)
{
digit = (char)(nb / mask);
++size;
nb -= mask * (double)digit;
mask /= 10.0;
ft_putchar(digit + '0');
}
if (prec > 0)
size += ft_printradix(nb, prec);
return (size);
}
7 changes: 4 additions & 3 deletions ft_putendl.c
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
#include <unistd.h>
#include "libft.h"

void ft_putendl(char const *s)
int ft_putendl(char const *s)
{
ft_putstr(s);
write(1, "\n", 1);
int len;
len = ft_putstr(s);
return (len + write(1, "\n", 1));
}
Empty file modified ft_putendl_fd.c
100644 → 100755
Empty file.
Empty file modified ft_putnbr.c
100644 → 100755
Empty file.
Empty file modified ft_putnbr_base.c
100644 → 100755
Empty file.
Empty file modified ft_putnbr_fd.c
100644 → 100755
Empty file.
22 changes: 22 additions & 0 deletions ft_putnbr_ll.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "libft.h"
#include <limits.h>

int ft_putnbr_ll(long long nbr)
{
char digit;
unsigned long size;

// long max
if (nbr < 0)
{
ft_putchar('-');
nbr = 0 - nbr;
}
digit = (char)(nbr % 10);
if (nbr >= 10)
size = ft_putnbr_ll(nbr / 10);
else
size = 1;
ft_putchar('0' + digit);
return (size);
}
30 changes: 30 additions & 0 deletions ft_putnbr_oct.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbroct.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tseguier <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/08/01 04:33:12 by tseguier #+# #+# */
/* Updated: 2014/08/01 04:35:47 by tseguier ### ########.fr */
/* */
/* ************************************************************************** */

#include "libft.h"

static const char *g_octbase = "01234567";

void ft_putnbr_oct(unsigned long long nb, unsigned int len)
{
char nb_act;

nb_act = nb % 8;
if (nb >= 8)
ft_putnbr_oct(nb / 8, len > 0 ? len - 1 : 0);
else if (len > 0)
{
while (--len > 0)
ft_putchar('0');
}
ft_putchar(g_octbase[(int)nb_act]);
}
16 changes: 16 additions & 0 deletions ft_putnbr_ull.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "libft.h"
#include <limits.h>

int ft_putnbr_ull(unsigned long long nbr)
{
char digit;
unsigned long size;

digit = (char)(nbr % 10);
if (nbr >= 10)
size = ft_putnbr_ull(nbr / 10);
else
size = 1;
ft_putchar('0' + digit);
return (size);
}
22 changes: 15 additions & 7 deletions ft_putnbrhex.c
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,27 @@

#include "libft.h"

const char *g_hexbase = "0123456789abcdef";
static const char *g_hexbase = "0123456789abcdef";
static const char *g_hexbase_maj = "0123456789ABCDEF";

void ft_putnbrhex(unsigned int nb, unsigned int len)
int ft_putnbrhex(unsigned long long nb, unsigned int len, int maj)
{
char nb_act;
int size;

nb_act = nb % 16;
size = 0;
if (nb >= 16)
ft_putnbrhex(nb / 16, len + 1);
else
size = ft_putnbrhex(nb / 16, len > 0 ? len - 1 : 0, maj);
else if (len > 0)
{
while (len++ < 8)
ft_putchar('0');
size = len - 1;
while (--len > 0)
ft_putchar('0');
}
ft_putchar(g_hexbase[(int)nb_act]);
if (maj)
ft_putchar(g_hexbase_maj[(int)nb_act]);
else
ft_putchar(g_hexbase[(int)nb_act]);
return (1 + size);
}
6 changes: 3 additions & 3 deletions ft_putstr.c
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
#include <unistd.h>
#include "libft.h"

void ft_putstr(char const *s)
int ft_putstr(char const *s)
{
if (!s)
write(1, "(NULL)", 6);
return (write(1, "(NULL)", 6));
else
write(1, s, ft_strlen(s));
return (write(1, s, ft_strlen(s)));
}
Empty file modified ft_putstr_fd.c
100644 → 100755
Empty file.
Empty file modified ft_strcat.c
100644 → 100755
Empty file.
Empty file modified ft_strchind.c
100644 → 100755
Empty file.
Empty file modified ft_strchr.c
100644 → 100755
Empty file.
Empty file modified ft_strclr.c
100644 → 100755
Empty file.
Empty file modified ft_strcmp.c
100644 → 100755
Empty file.
Empty file modified ft_strcpy.c
100644 → 100755
Empty file.
Empty file modified ft_strcsub.c
100644 → 100755
Empty file.
Empty file modified ft_strdel.c
100644 → 100755
Empty file.
Empty file modified ft_strdup.c
100644 → 100755
Empty file.
Empty file modified ft_strequ.c
100644 → 100755
Empty file.
Empty file modified ft_striter.c
100644 → 100755
Empty file.
Empty file modified ft_striteri.c
100644 → 100755
Empty file.
Empty file modified ft_strjoin.c
100644 → 100755
Empty file.
Empty file modified ft_strlcat.c
100644 → 100755
Empty file.
Empty file modified ft_strlen.c
100644 → 100755
Empty file.
Empty file modified ft_strmap.c
100644 → 100755
Empty file.
Empty file modified ft_strmapi.c
100644 → 100755
Empty file.
Empty file modified ft_strncat.c
100644 → 100755
Empty file.
Empty file modified ft_strncmp.c
100644 → 100755
Empty file.
Empty file modified ft_strncpy.c
100644 → 100755
Empty file.
Empty file modified ft_strnequ.c
100644 → 100755
Empty file.
Empty file modified ft_strnew.c
100644 → 100755
Empty file.
Empty file modified ft_strnstr.c
100644 → 100755
Empty file.
Empty file modified ft_strrchind.c
100644 → 100755
Empty file.
Empty file modified ft_strrchr.c
100644 → 100755
Empty file.
Empty file modified ft_strrev.c
100644 → 100755
Empty file.
Empty file modified ft_strsepjoin.c
100644 → 100755
Empty file.
Empty file modified ft_strsplit.c
100644 → 100755
Empty file.
Empty file modified ft_strstr.c
100644 → 100755
Empty file.
Empty file modified ft_strsub.c
100644 → 100755
Empty file.
Empty file modified ft_strtabcpy.c
100644 → 100755
Empty file.
Empty file modified ft_strtabdel.c
100644 → 100755
Empty file.
Empty file modified ft_strtabrealloc.c
100644 → 100755
Empty file.
Empty file modified ft_strtrim.c
100644 → 100755
Empty file.
Empty file modified ft_tolower.c
100644 → 100755
Empty file.
Empty file modified ft_toupper.c
100644 → 100755
Empty file.
Empty file modified get_next_line.c
100644 → 100755
Empty file.
11 changes: 7 additions & 4 deletions headers/libft.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,19 @@
** Affichage
*/
void *ft_print_memory(void *addr, unsigned int size);
void ft_putnbrhex(unsigned int nb, unsigned int len);
void ft_putchar(char c);
void ft_putstr(char const *s);
void ft_putendl(char const *s);
int ft_putnbrhex(unsigned long long nb, unsigned int len, int maj);
void ft_putnbr_oct(unsigned long long nb, unsigned int len);
int ft_putchar(char c);
int ft_putstr(char const *s);
int ft_putendl(char const *s);
void ft_putnbr(int n);
void ft_putchar_fd(char c, int fd);
void ft_putstr_fd(char const *s, int fd);
void ft_putendl_fd(char const *s, int fd);
void ft_putnbr_fd(int n, int fd);
void ft_putnbr_base(int nbr, char *base);
int ft_putnbr_ll(long long nbr);
int ft_putnbr_ull(unsigned long long nbr);
/*
** Memory
*/
Expand Down
Empty file modified main.c
100644 → 100755
Empty file.

0 comments on commit d8443b8

Please sign in to comment.