php_cli_process_title.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 5 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2016 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. /* $Id$ */
  19. #ifdef HAVE_CONFIG_H
  20. #include "config.h"
  21. #endif
  22. #include "php.h"
  23. #include "php_cli_process_title.h"
  24. #include "ps_title.h"
  25. /* {{{ proto boolean cli_set_process_title(string arg)
  26. Return a boolean to confirm if the process title was successfully changed or not */
  27. PHP_FUNCTION(cli_set_process_title)
  28. {
  29. char *title = NULL;
  30. int title_len;
  31. int rc;
  32. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &title, &title_len) == FAILURE) {
  33. return;
  34. }
  35. rc = set_ps_title(title);
  36. if (rc == PS_TITLE_SUCCESS) {
  37. RETURN_TRUE;
  38. }
  39. php_error_docref(NULL TSRMLS_CC, E_WARNING, "cli_set_process_title had an error: %s", ps_title_errno(rc));
  40. RETURN_FALSE;
  41. }
  42. /* }}} */
  43. /* {{{ proto string cli_get_process_title()
  44. Return a string with the current process title. NULL if error. */
  45. PHP_FUNCTION(cli_get_process_title)
  46. {
  47. int length = 0;
  48. const char* title = NULL;
  49. int rc;
  50. if (zend_parse_parameters_none() == FAILURE) {
  51. return;
  52. }
  53. rc = get_ps_title(&length, &title);
  54. if (rc != PS_TITLE_SUCCESS) {
  55. php_error_docref(NULL TSRMLS_CC, E_WARNING, "cli_get_process_title had an error: %s", ps_title_errno(rc));
  56. RETURN_NULL();
  57. }
  58. RETURN_STRINGL(title, length, 1);
  59. }
  60. /* }}} */
  61. /*
  62. * Local variables:
  63. * tab-width: 4
  64. * c-basic-offset: 4
  65. * End:
  66. * vim600: noet sw=4 ts=4 fdm=marker
  67. * vim<600: noet sw=4 ts=4
  68. */