open_creat.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (c) 2011-2012 Nokia Corporation and/or its subsidiary(-ies).
  3. * All rights reserved.
  4. * This component and the accompanying materials are made available
  5. * under the terms of the License "Eclipse Public License v1.0"
  6. * which accompanies this distribution, and is available
  7. * at the URL "http://www.eclipse.org/legal/epl-v10.html".
  8. *
  9. * Initial Contributors:
  10. * Nokia Corporation - initial contribution.
  11. *
  12. * Contributors:
  13. *
  14. * Description:
  15. * Program for testing some file operations
  16. *
  17. */
  18. #include <fcntl.h>
  19. #include <dirent.h>
  20. #include <sys/types.h>
  21. #include <sys/stat.h>
  22. #include <unistd.h>
  23. #include <errno.h>
  24. #include <string.h>
  25. #include <stdio.h>
  26. #define EOK 0
  27. #define ENOPATH 1
  28. int main(int argc, char *argv[])
  29. {
  30. struct stat stb;
  31. int fd, res=0;
  32. if (argc > 1)
  33. {
  34. fd = open(argv[1], O_CREAT|O_RDWR,0666);
  35. if (fd <= 0)
  36. {
  37. perror("creat failed: ");
  38. res = errno;
  39. }
  40. else
  41. {
  42. write(fd,"Hello World\n", 12);
  43. close(fd);
  44. }
  45. }
  46. else
  47. {
  48. fprintf(stderr,"Not enough args\n");
  49. res = -1;
  50. }
  51. return res;
  52. }