minishell
ft_putnbr_fd.c File Reference
#include <stddef.h>
#include "ft_put.h"
Include dependency graph for ft_putnbr_fd.c:

Go to the source code of this file.

Macros

#define NUM_STR_BUF_LEN   (12)
 

Functions

static char * reverse_str (char *str)
 
static long ft_absl (long v)
 
void ft_putnbr_fd (int n, int fd)
 

Macro Definition Documentation

◆ NUM_STR_BUF_LEN

#define NUM_STR_BUF_LEN   (12)

Definition at line 16 of file ft_putnbr_fd.c.

Function Documentation

◆ ft_absl()

static long ft_absl ( long  v)
static

Definition at line 40 of file ft_putnbr_fd.c.

41 {
42  if (v >= 0)
43  return (v);
44  else
45  return (v * -1);
46 }
Here is the caller graph for this function:

◆ ft_putnbr_fd()

void ft_putnbr_fd ( int  n,
int  fd 
)

Definition at line 48 of file ft_putnbr_fd.c.

49 {
50  char num_str_buf[NUM_STR_BUF_LEN];
51  int buf_pos;
52  long long_n;
53 
54  if (0 <= n && n <= 9)
55  {
56  ft_putchar_fd('0' + n, fd);
57  return ;
58  }
59  buf_pos = 0;
60  long_n = ft_absl(n);
61  while (long_n != 0)
62  {
63  num_str_buf[buf_pos++] = (long_n % 10) + '0';
64  long_n /= 10;
65  }
66  if (n < 0)
67  num_str_buf[buf_pos++] = '-';
68  num_str_buf[buf_pos] = '\0';
69  ft_putstr_fd(reverse_str(num_str_buf), fd);
70 }
void ft_putchar_fd(char c, int fd)
Definition: ft_putchar_fd.c:16
void ft_putstr_fd(char *s, int fd)
Definition: ft_putstr_fd.c:17
static long ft_absl(long v)
Definition: ft_putnbr_fd.c:40
static char * reverse_str(char *str)
Definition: ft_putnbr_fd.c:18
#define NUM_STR_BUF_LEN
Definition: ft_putnbr_fd.c:16
Here is the call graph for this function:

◆ reverse_str()

static char* reverse_str ( char *  str)
static

Definition at line 18 of file ft_putnbr_fd.c.

19 {
20  char *str_top;
21  char *str_end;
22  char tmp;
23 
24  if (str == NULL)
25  return (NULL);
26  str_top = str;
27  str_end = str;
28  while (*str_end != '\0')
29  str_end++;
30  str_end -= 1;
31  while (str_top < str_end)
32  {
33  tmp = *str_end;
34  *str_end-- = *str_top;
35  *str_top++ = tmp;
36  }
37  return (str);
38 }
Here is the caller graph for this function: