php_cli_process_title.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 7 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2018 The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 3.01 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.php.net/license/3_01.txt |
  11. | If you did not receive a copy of the PHP license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@php.net so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Author: Keyur Govande (kgovande@gmail.com) |
  16. +----------------------------------------------------------------------+
  17. */
  18. #ifdef HAVE_CONFIG_H
  19. #include "config.h"
  20. #endif
  21. #include "php.h"
  22. #include "php_cli_process_title.h"
  23. #include "ps_title.h"
  24. /* {{{ proto bool cli_set_process_title(string arg)
  25. Return a boolean to confirm if the process title was successfully changed or not */
  26. PHP_FUNCTION(cli_set_process_title)
  27. {
  28. char *title = NULL;
  29. size_t title_len;
  30. int rc;
  31. if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &title, &title_len) == FAILURE) {
  32. return;
  33. }
  34. rc = set_ps_title(title);
  35. if (rc == PS_TITLE_SUCCESS) {
  36. RETURN_TRUE;
  37. }
  38. php_error_docref(NULL, E_WARNING, "cli_set_process_title had an error: %s", ps_title_errno(rc));
  39. RETURN_FALSE;
  40. }
  41. /* }}} */
  42. /* {{{ proto string cli_get_process_title()
  43. Return a string with the current process title. NULL if error. */
  44. PHP_FUNCTION(cli_get_process_title)
  45. {
  46. int length = 0;
  47. const char* title = NULL;
  48. int rc;
  49. if (zend_parse_parameters_none() == FAILURE) {
  50. return;
  51. }
  52. rc = get_ps_title(&length, &title);
  53. if (rc != PS_TITLE_SUCCESS) {
  54. php_error_docref(NULL, E_WARNING, "cli_get_process_title had an error: %s", ps_title_errno(rc));
  55. RETURN_NULL();
  56. }
  57. RETURN_STRINGL(title, length);
  58. }
  59. /* }}} */
  60. /*
  61. * Local variables:
  62. * tab-width: 4
  63. * c-basic-offset: 4
  64. * End:
  65. * vim600: noet sw=4 ts=4 fdm=marker
  66. * vim<600: noet sw=4 ts=4
  67. */