Changeset 42964a7 in mainline
- Timestamp:
- 2018-08-02T13:54:33Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 3b10ae36
- Parents:
- 233a3a06
- git-author:
- Jiri Svoboda <jiri@…> (2018-08-01 18:54:24)
- git-committer:
- Jiri Svoboda <jiri@…> (2018-08-02 13:54:33)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/contacts/contacts.c
r233a3a06 r42964a7 79 79 80 80 static errno_t contacts_unmarshal(sif_node_t *, contacts_t *); 81 static contacts_entry_t *contacts_first(contacts_t *); 82 static contacts_entry_t *contacts_next(contacts_entry_t *); 83 static void contacts_entry_delete(contacts_entry_t *); 81 84 82 85 /** Open contacts repo or create it if it does not exist. … … 287 290 static errno_t contacts_delete_contact(contacts_t *contacts) 288 291 { 292 nchoice_t *choice = NULL; 293 contacts_entry_t *entry; 294 sif_trans_t *trans = NULL; 295 errno_t rc; 296 void *sel; 297 298 rc = nchoice_create(&choice); 299 if (rc != EOK) { 300 assert(rc == ENOMEM); 301 printf("Out of memory.\n"); 302 goto error; 303 } 304 305 rc = nchoice_set_prompt(choice, "Select contact to delete"); 306 if (rc != EOK) { 307 assert(rc == ENOMEM); 308 printf("Out of memory.\n"); 309 goto error; 310 } 311 312 entry = contacts_first(contacts); 313 while (entry != NULL) { 314 rc = nchoice_add(choice, entry->name, (void *)entry, 0); 315 if (rc != EOK) { 316 assert(rc == ENOMEM); 317 printf("Out of memory.\n"); 318 goto error; 319 } 320 321 entry = contacts_next(entry); 322 } 323 324 rc = nchoice_add(choice, "Cancel", NULL, 0); 325 if (rc != EOK) { 326 assert(rc == ENOMEM); 327 printf("Out of memory.\n"); 328 goto error; 329 } 330 331 rc = nchoice_get(choice, &sel); 332 if (rc != EOK) { 333 printf("Error getting user selection.\n"); 334 return rc; 335 } 336 337 if (sel != NULL) { 338 entry = (contacts_entry_t *)sel; 339 340 rc = sif_trans_begin(contacts->repo, &trans); 341 if (rc != EOK) 342 goto error; 343 344 sif_node_destroy(trans, entry->nentry); 345 346 rc = sif_trans_end(trans); 347 if (rc != EOK) 348 goto error; 349 350 trans = NULL; 351 352 list_remove(&entry->lentries); 353 contacts_entry_delete(entry); 354 } 355 356 nchoice_destroy(choice); 289 357 return EOK; 358 error: 359 if (trans != NULL) 360 sif_trans_abort(trans); 361 if (choice != NULL) 362 nchoice_destroy(choice); 363 return rc; 290 364 } 291 365 … … 296 370 static void contacts_close(contacts_t *contacts) 297 371 { 298 printf("Closing repo %p\n", contacts->repo); 372 contacts_entry_t *entry; 373 299 374 sif_close(contacts->repo); 375 376 entry = contacts_first(contacts); 377 while (entry != NULL) { 378 list_remove(&entry->lentries); 379 contacts_entry_delete(entry); 380 entry = contacts_first(contacts); 381 } 382 300 383 free(contacts); 301 384 } … … 331 414 332 415 return list_get_instance(link, contacts_entry_t, lentries); 416 } 417 418 /** Delete entry structure from memory. 419 * 420 * @param entry Contacts entry 421 */ 422 static void contacts_entry_delete(contacts_entry_t *entry) 423 { 424 if (entry == NULL) 425 return; 426 427 if (entry->name != NULL) 428 free(entry->name); 429 430 free(entry); 333 431 } 334 432
Note:
See TracChangeset
for help on using the changeset viewer.