-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include "holberton.h" | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <limits.h> | ||
|
||
/** | ||
* main - check the code for Holberton School students. | ||
* | ||
* Return: Always 0. | ||
*/ | ||
int main(void) | ||
{ | ||
char *c; | ||
int *i; | ||
float *f; | ||
double *d; | ||
|
||
c = malloc_checked(sizeof(char) * 1024); | ||
printf("%p\n", (void *)c); | ||
i = malloc_checked(sizeof(int) * 402); | ||
printf("%p\n", (void *)i); | ||
f = malloc_checked(sizeof(float) * 100000000); | ||
printf("%p\n", (void *)f); | ||
d = malloc_checked(INT_MAX); | ||
printf("%p\n", (void *)d); | ||
free(c); | ||
free(i); | ||
free(f); | ||
free(d); | ||
return (0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include "holberton.h" | ||
/** | ||
* malloc_checked - alloctes memory using malloc. | ||
* @b: size. | ||
* Return: returns pointer, otherwise 98 on fail. | ||
*/ | ||
void *malloc_checked(unsigned int b) | ||
{ | ||
void *temp; | ||
|
||
temp = malloc(b); | ||
if (temp == NULL) | ||
{ | ||
exit(98); | ||
} | ||
return (temp); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
0x0B-more_malloc_free | ||
|
||
add content here... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include <unistd.h> | ||
|
||
/** | ||
* * _putchar - writes the character c to stdout | ||
* * @c: The character to print | ||
* * | ||
* * Return: On success 1. | ||
* * On error, -1 is returned, and errno is set appropriately. | ||
* */ | ||
int _putchar(char c) | ||
{ | ||
return (write(1, &c, 1)); | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#ifndef HOLBERTON | ||
#define HOLBERTON | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
void *malloc_checked(unsigned int b); | ||
int _putchar(char c); | ||
|
||
#endif |