30 const size_t name_length = strlen(
name);
33 fprintf(stderr,
"Name of product \"%s\" exceeds maximum character limit.\n",
name);
40 if (product == NULL) {
41 fprintf(stderr,
"Could not create product \"%s\": %s\n",
name, strerror(errno));
47 strncpy(product->
name,
name, name_length);
48 product->
name[name_length] =
'\0';
66 return fprintf(buffer,
"%s\n%d\n", this->
name, this->
quantity);
71 if (modifier < 0 && (
unsigned int) -modifier > this->
quantity)
80 const unsigned int lhs_quantity = (*(
const struct Product **) product_lhs)->quantity;
81 const unsigned int rhs_quantity = (*(
const struct Product **) product_rhs)->quantity;
83 if (lhs_quantity < rhs_quantity)
86 if (lhs_quantity > rhs_quantity)
struct Product * product_create(const unsigned int id, const char *const name, const unsigned int quantity)
int product_file_serialise(const struct Product *const this, FILE *const buffer)
void product_delete(struct Product **this)
int product_ptr_compare(const void *const product_lhs, const void *const product_rhs)
bool product_modify_quantity(struct Product *this, const int modifier)
Product class specification.
#define MAX_NAME_LENGTH
Maximum number of bytes for a Product name, excluding the NULL-terminator.
The Product represents a single product with a unique numerical identifier, human-readable name,...
char name[MAX_NAME_LENGTH+1]
NULL-terminated human-readable name of the Product.
unsigned int id
Numerical identifier of the Product.
unsigned int quantity
Non-negative number of Product items in stock.
int product_report_serialise(const struct Product *this, FILE *buffer)
Serialise the given Product in the report format to the given buffer.